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
 Reshape Long Missing Values ErrorMy dataset is in time series format.
I am converting it to a panel using the following code:
Code… Reshape Long Missing Values ErrorMy dataset is in time series format.
I am converting it to a panel using the following code:
Code…
 Merging 3 data setsGood evening all. I am looking for some help merging 3 data sets.
All 3 data sets are sorted by pati… Merging 3 data setsGood evening all. I am looking for some help merging 3 data sets.
All 3 data sets are sorted by pati…
 Twoway line by countyHi everyone,
For my Panel Data descriptive Analysis I am trying to graph the development of Chargin… Twoway line by countyHi everyone,
For my Panel Data descriptive Analysis I am trying to graph the development of Chargin…
 Different resutls between xtreg and xtivreg2
I recently ran into an issue with xtivreg2. I find that the coefficient estimates are so much diffe… Different resutls between xtreg and xtivreg2
I recently ran into an issue with xtivreg2. I find that the coefficient estimates are so much diffe…
 Marginsplot, addplot - adjustmentHello,
using the command: - marginsplot, addplot(hist...)-, I got this graph:
Array
I would like to… Marginsplot, addplot - adjustmentHello,
using the command: - marginsplot, addplot(hist...)-, I got this graph:
Array
I would like to…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid name error in foreach loop
Post a Comment