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
Dealing w/ multicollinearity in logit model w/ FE (state, month)I’m conducting an analysis where I want to know how my outcome of interest, reemployment probability…
xthybrid and interactionsHi statalist community, I am using xthybrid command for the analysis of data. How to handle interac…
What does "star" option in pwcorr mean?Normally I used pwcorr to have a correlation matrix. And for such a command, we have a star option. …
Why using the same code but can run in one machine and cannot run in another machine resulting r(123)?Hi all, I suspect the problems previously but I can confirm today that some code of mine can work i…
cannot run GMMDear Statalist, I am using stata v.14... I have unbalanced panel data with T = 17 and N = 18. I mo…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string values to numeric
Post a Comment