Hello there,
I have two variables, income of individuals from year 1968 to 2017 and their ages for the same years. I want to create a variable which indicates income for specific age. Like income of each individual at the age of 40. I wrote the following loop but it assigned 2017's income for all ages.
generate labory40=.
foreach x of varlist labory1968-labory2017{
foreach y of varlist age1968-age2017{
replace labory40=`x' if `y'==40
}
}
generate labory41=.
foreach x of varlist labory1968-labory2017{
foreach y of varlist age1968-age2017{
replace labory41=`x' if `y'==41
}
}
.
.
.
Any help is highly appreciated,
Related Posts with foreach loop
How to*create a POST variable to be used for Difference-in-Differences for panel dataI want to create 2 POST variables to observe the effects of a merger on a company. Problem: The rec…
Finding unique values between variablesI am trying to find values that exist in one data set and not another. I have a child table that lik…
How to*create a POST variable to be used for Difference-in-Differences for panel dataI want to create 2 POST variables to observe the effects of a merger on a company. Problem: The rec…
global or local seed setting in loopDear all, I want to run a loop in which the seed changes for every single run: Code: forvalues m…
interpreting marginal effect of logit dummy regressors at 1.I have a problem interpreting the marginal effect of a dummy variable in a logit model. (I am using …
Subscribe to:
Post Comments (Atom)
0 Response to foreach loop
Post a Comment