I would appreciate a hand with concise code to convert variable values that are listed alphabetically (i.e. currently a to q (representing waves in a panel dataset) to numerical values (1 - 17). While I did refer to a number of previous threads, I struggled to find a solution, including Cox (2002b, 2003) and Stata help files.
My original code is clearly unnecessarily lengthy:
e.g. gen wavenum = .
replace wavenum = 1 if(wave=="a")
replace wavenum = 2 if(wave=="b")
replace wavenum = 3 if(wave=="c")
etc.
Essentially I was wondering if/how I could use 'foreach' or 'forvalues' to address this problem more succinctly .
Thank you in advance.
Related Posts with Converting string values to numeric
Longitudinal latent class trajectory analysis guidanceDear Stata users, I am trying to perform longitudinal analysis for the first time, so would appreci…
Using pcarrowi dyanmically?Hello everyone, Is there any way to use pcarrowi command dynamically? I'm trying to find a way to i…
Counting variables with a stub across rows in frame, add count to new columnHi all, I am a newbie to Stata, recently transitioned from R. I am struggling with combining the le…
why noconst option generate so different results in Nlogit?Dear experts, I used Nlogit to analyse data. First, I did not include noconst in level 2 equation. …
Drop empty variables when importing spss into stataI have an spss dataset that has ~27000 variables, but only ~500 include any values. The rest are bla…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string values to numeric
Post a Comment