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
Mediation in generalized differnce-in-difference.Dear All, I want to estimate the impact of a state policy, adopted by different states at different…
repeated time values in sample problemHello, I have panel data on cryptocurrencies. Uniquely identified by coin's rank and date. I used ts…
run all do files in folder sequentiallyHi there - I would like to run all do files in one particular folder sequentially. The order in whic…
Problem with LR test in a multilevel modelDear Statalist, I am trying to figure out if it is necessary to include a random intercept in a thr…
Multiple imputation takes foreverHello everyone, I'd like to get some help with multiple imputation. I searched everywhere but could…
Subscribe to:
Post Comments (Atom)
0 Response to difficulty with forvalues/foreach naming
Post a Comment