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
XSMLE dynamic SDM where beta is constrained to = 0Dear list members, I have a special request estimating a dynamic spatial durbin model. I would like…
Regression rich text file issueHello, I am attempting to transfer the regression to a rich text file. For some reason my regression…
xtpdyn marginsDear all, I've encountered a problem when implementing xtpdyn postestimation. Using this example: xt…
Importing variable with special characters, strings and numbersDear Stata users, I am experiencing problems in importing a variable from a csv file. This variable…
Testing for difference in marginal effects at two values of same continuous independent variableHi all, and thanks in advance for any responses. I'm estimating the following model: mlogit enroll_…
Subscribe to:
Post Comments (Atom)
0 Response to foreach loop
Post a Comment