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
Adjusted/Within/Between R squaredHi, I would be very grateful if someone could confirm whether my understanding is correct. I ran a …
Failed ramesy RESET testHi, Im fairly new to stata, i've just manually run a RESET test on my panel data and it failed. I u…
.ado Programming in Stata without invoking mata: Errors while passing arguments to functionLevel: Beginner Trying to write an .ado file. This is how it looks. When I was debugging this line …
Multinomial logit or -gsem- which is best for simultaneous choiceHello, I am looking for some suggestions to choose an appropriate model for my research. I am tryin…
How to use hp filter on different groupsI have GDP data for each state from the last 10 years, and I want to use hp filter on each state's t…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string values to numeric
Post a Comment