Dear Stata Forum,
I got a question regarding a Monte Carlo simulation I want to obtain.
I have a dataset that looks like a classical unbalanced panel with something over 2000 observations:
What I want to do is
I try this via the following code:
My problem is now that STATA returns the error “beta already defined”. Can anybody tell me how to save the coefficients and standard errors in my file “sim_mem”?
Many thanks in advance for your help !
Regards,
John
I got a question regarding a Monte Carlo simulation I want to obtain.
I have a dataset that looks like a classical unbalanced panel with something over 2000 observations:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id Year var1) double var2 1 2004 15.414348 .28 1 2005 15.98485 .1585459536 2 2004 10.96554 0 2 2005 10.91454 0 2 2006 11.595363 0 3 2004 11.55106 0 3 2006 11.56106 0 4 2003 14.85976 0 4 2004 14.536894 0 5 2004 11.61788 0 5 2005 11.915888 0 6 2005 13.998934 0 6 2003 13.55726 0 6 2004 13.90656 0 7 2005 15.09606 .5415 7 2004 15.059196 .5418 end
What I want to do is
- randomly select 7 observations of each id via a Monte Carlo simulation,
- do a regression
- Save betas and standard errors in a file
- Repeat this 100 times
I try this via the following code:
Code:
set seed 12456 postfile sim_mem beta SE using simresults, replace forvalues i=1/100 { capture drop non_event sample 11, count by(id) reg var1 var2 gen beta = _b[var2] gen SE = _se[var2] post sim_mem (beta) (SE) } postclose sim_mem
Many thanks in advance for your help !
Regards,
John
Comment