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!
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!
Comment