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
Test for two mean and standard deviation with unknown sample size.Hi, I have lung function data (mean and SD) for two time point, say, admission and discharge for 20 …
regressions with Fixed Effect and CCEMG/CCEP give different resultsDear all, I want to ask you about results of fixed effect and CCEP/CCEMG. I regressed my variables…
Problems with lower bound for a proportion below 0 for "teffects" commandDear Statalisters, I'm using Statalist 15.1. By using the "teffects" command in a case of binary out…
Logit regressionI want to run logit regression. My dependent var is =1 if firm pay dividend and 0 otherwise. But my …
Network Analysis-nwcommandsHi, I am using the nwcommands package to run some social network analysis. I am facing two issues-…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid name error in foreach loop
Post a Comment