Hi,
Same title as a similar post from 2020 which did not answer my problem...
I am trying to run a foreach loop with the following code:
foreach item in 19T 19U 24T 29U 44T 49U 64V{
gen `item'=amount if item==`item'
}
Error I get is:
19T invalid name
item is already a variable, first few lines look line this:
19T
19U
24T
29U
34T
39U
(the items will repeat, so 19T will show up multiple times in the item variable)
amount is another variable, first few lines:
465299
8137124
38958
1410000
98959
1399849
What I want is to generate new variables with the amount that corresponds to the desired item code. for example:
New variable: 19T
First few lines:
465299
.
.
.
.
.
[another value for when 19T shows up again in the data]
New variable: 19U
First few lines:
8137124
.
.
.
etc.....
Hopefully this makes sense. I can clarify further if need be. Thank you in advance for any advice!
Related Posts with Invalid name error in foreach loop
Dropping groups of individuals where not at least one object possess a certain characteristicDear community, I have a somewhat tricky problem: I grouped several observations together according…
Individual-invariant variables in FEHello, I am sorry if this topic has come up before - however, I did searched for an answer and faile…
regression over different number of observationsHi everyone I would like to regress each variable separately on one independent variable. Furthermo…
Income Elasticity with Logit ModelHi, This is my model: Code: logit smoker lninc Where lninc, is the log transformation of the in…
Assigning a result from summarize to a variableHi everyone, I want to sum a variable and then assign its highest value +1 to an observation. The v…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid name error in foreach loop
Post a Comment