I am relatively new to STATA and the loop functions.
I have a panel dataset with 1,000,000 observations over 1,000 panel units.
As part of some subsample analysis, I would like to run the same regression over each individual panel unit (so 1,000 regressions in total). Each panel is denoted by the variable 'id', which takes the values of 1-1,000.
So far I have the following code:
Code:
forvalues i = 1/1000 { preserve keep if id == `i' eststo: regress y x restore } esttab _all
1. If I drop some observations, resulting in some individual panel units being removed from the dataset (say for example there are no observations for id = 185) then the loop stops after running the regression for id = 184. Is there a way to overcome this?
2. Another (more minor) issue is that the output for each individual regression is missing any indication of what id it belongs to. I realise they will be run sequentially, but was wondering if there is an easy way to 'label' the regressions as they are estimated to prevent any errors in interpretation.
Thanks in advance for any assistance.
Regards,
Paul
0 Response to Loops with missing IDs
Post a Comment