I have a varlist called 'surgery' containing numbers from 1-5.
I would like to compute calculations of the dataset foreach values from 1-5 with dropping the other values and save the results in an exelfile on separate sheets.
I thought about coding something like this:
Code:
save final_set.dta, replace foreach var of varlist surgery { keep if surgery ==1/2/3/4/5 here come many calculations..... here come many calculations..... here come many calculations..... putexcel set final_results.xls, sheet("final_results_surgery_1/2/3/4/5") modify clear all use final_set.dta }
In the first loop I want to keep only surgery==1 and save the results in "final_results_surgery_1"
In the second loop I want to keep only surgery==2 and save the results in "final_results_surgery_2"
.....
0 Response to Loop
Post a Comment