Dear Statalist,
I am new to Stata and trying to create a loop. I am looking at lifetime earnings, and want to be able to plot and get values for specific quantiles at each age.
Here is the code I have tried:
foreach pct of varlist 10 20 30 50 70 80 {
egen female`pct'=pctile(salary) if female==1 & unigrad==1, p(`pct') by(age)
}
To which Stata returns "invalid name"
Similarly, I am using the user written ado file "rifreg", and would like to run it over the same quantiles again by gender.
Running the following:
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(.10)
predict fem10
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(.20)
predict fem20
ect. has worked, but I would like to loop it also to save time.
I have tried the following to the same error message:
foreach pct of varlist 10 20 30 50 70 80 {
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(`pct')
predict fem`pct'
}
Best,
Gabrielle
I am new to Stata and trying to create a loop. I am looking at lifetime earnings, and want to be able to plot and get values for specific quantiles at each age.
Here is the code I have tried:
foreach pct of varlist 10 20 30 50 70 80 {
egen female`pct'=pctile(salary) if female==1 & unigrad==1, p(`pct') by(age)
}
To which Stata returns "invalid name"
Similarly, I am using the user written ado file "rifreg", and would like to run it over the same quantiles again by gender.
Running the following:
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(.10)
predict fem10
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(.20)
predict fem20
ect. has worked, but I would like to loop it also to save time.
I have tried the following to the same error message:
foreach pct of varlist 10 20 30 50 70 80 {
qui rifreg income age age2 age3 age4 if age>21 & age<60 & female==1 & unigrad==1, quantile(`pct')
predict fem`pct'
}
Best,
Gabrielle
Comment