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
Regression discontinuity design - discrete running variableI am conducting a sharp RD, with my running variable being the age of the woman in months. I am tryi…
Factor not found in list of covariatesHello, I have tried searching for an answer to my question but have not be able to find one. I am r…
On the regular expression of StataI found regular expression of Stata very confusing. For instance: Code: disp regexm("010-11223344",…
Generating a new variable that contains only some values of other variablesDear all, I have a set of variables (i.e., v1 to V) from which I would like to extract some single …
TestTesting …
Subscribe to:
Post Comments (Atom)
0 Response to Converting string values to numeric
Post a Comment