hi all, I'm trying to generate a new set of variables and struggling with the naming --
I have a variable of "state" that has a number assigned to each state, and a variable for 2016 presidential election results. I want to create a new set of variables, one for each state, of the presidential vote share.
forvalues j = 1/50 {
generate pres_`j'=.
replace pres_`j'=pres2016 if state==`j'
}
This works, but I want the output to be the state names like pres_alabama, pres_alaska, pres_arizona ...
Any idea how to do this? Should I be using the foreach command instead of forvalues? All help is greatly appreciated!
Related Posts with difficulty with forvalues/foreach naming
Mixed logit modelsI'm interested to develop a mixed logit model for crash injury severity. My response variable is "in…
Combining two matrices in one VariableDear all, my university is using the Stata version with max matsize = 800. I am working with a data…
xtsccDears, I have question regarding XTSCC. As I read this can be used to deal with cross-section depen…
Import oaxaca result in latexCould you please share me a stata code to import Oaxaca result in latex. I examine the wage gap amon…
droping multiple observationsMy data looks like the one below. and I want to delete the observations that dont have hhid (the thr…
Subscribe to:
Post Comments (Atom)
0 Response to difficulty with forvalues/foreach naming
Post a Comment