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 xtreg i.years - multiple years omittedHello, I am doing a research about the effect of gender diversity on firm performance with panel da…
Generating values of a variable based on the values of other variables.Hi, In my data, I have portfolio id, port_ret, first, date, count, have, and want. Id is simply th…
Delete non-matching portions of string variableHi. I have a local (defined below). I also have a string variable Event. I want to only retain words…
table that shows average number of appliances owned by household typeDear all, I am stuck with the following challenge: I have household data with the information: hous…
Bootstrapping Confidence Interval for bins/groupsHello everyone, First my dataset: The bins were created by recoding my initial x for a specific dat…
Subscribe to:
Post Comments (Atom)
0 Response to difficulty with forvalues/foreach naming
Post a Comment