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
Panel data regression - several dummy variables or xtreg, with more than fixed-effect variableHello, I'm trying to work out the advantages/disadvantages of using xtreg with a panel dataset, or u…
file miest.ster already exists I have been trying to run some imputation modelling and am running into this error code when I try …
Generate distinct id for dyads in groups in long formatDear Statalist. I have a dataset of dyads in groups in long format. I need to generate a variable "…
Sargan test (overidentifying restrictions)Hi every one I have an inquiry about why I sometimes get Sargan score and Bessnman and Sometimes onl…
from option - mixlogit commandHello all! I am trying to run a mixlogit with a specific restriction on the Standard Deviation of o…
Subscribe to:
Post Comments (Atom)
0 Response to difficulty with forvalues/foreach naming
Post a Comment