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
STATA coefplot: plot other coefficients benchmark to one coefficientI'm using coefplot to plot the coefficients on xlag3, xlag2, xlag1, x, xlead1,xlead2,xlead3 from my …
Treat numeric variables as factor variablesI have a dataset with 3500 companies. Each company has a unique company ID (variable name is id), wh…
Plotting interactions so their cumulative effects can be illustratedHi, I am trying to plot three categorical by continuous interactions on top of one another so that …
Graph bar for categorical variable, but sorted in prespecified orderThis is a stunningly simple problem and I know there is a stunningly simple answer, but I can't figu…
SVYSET and SVY:tab helpHello, I have the following two SPSS commands. This is what I have from the SPSS codebook: CSPLAN A…
Subscribe to:
Post Comments (Atom)
0 Response to foreach loop
Post a Comment