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
Neural NetworkHi everyone, I have just recently uploaded a neural network module for Stata. brain.ado is neural …
Different n, R² and RMSE: Choosing between A) means in dataset / B) dataset of meansHello, this might be easily answered: Which of the following options must I choose for a "correct" b…
Detecting autocorrelation in DiD: can I use xtserial?Hello, I am working on the following Diff in diff model in stata: reg ln_sales = i.treatment +trea…
regress, unbiased standard errors?Hello, I would like to know if the command regress corrects for n-k to get the unbiased standard err…
Type of GMM Estimator With ivreg2 Dear members, In our research, we use the stata command “ivreg2” with year and country dummies in …
Subscribe to:
Post Comments (Atom)
0 Response to Invalid name error in foreach loop
Post a Comment