Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Bootstrap with Panel Data


From   "Tim R. Sass" <tsass@coss.fsu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Bootstrap with Panel Data
Date   Tue, 03 Jan 2006 12:34:17 -0500

Dear Statalisters -

I am trying to bootstrap a user-written command using an unbalanced panel consisting of a few thousand individuals observed up to four times each. I am using Stata 9.1 for Windows 64. The command runs fine without the bootstrap. It also runs properly when I first take a single bsample and then execute the command. Further, if I ignore the panel properties of the data and run the bootstrap without the cluster() and idcluster() options it runs fine. The problem occurs when I utilize the cluster() and idcluster() options I get the error message:

repeated time values within panel
the most likely cause for this error is misspecifying the cluster() idcluster()

I have read the FAQs "How do I obtain bootstrapped standard errors with panel data" and "Dealing with reports of repeated time values within panel" and I seem to be doing everything correctly. I currently have the idcluster variable (new_i) being created prior to executing the bootstrap, but I have also tried not creating it before the bootstrap and I get the same error.

The relevant output follows. Any help would be greatly appreciated.

Tim




. gen new_i=student;

. program iterative_fe, eclass;
1. version 9.1;
2. * ******************************************************* ;
. * Define Variables ;
. * ******************************************************* ;
. * Name for result vector;
. tempname bb;
3. * Define dependent and explanatory variables;
. local depvar "nrtmgain" ;
4. local expvar "nschools strucmove nonstrucmove
> tgrde_05
> t2001 t2002 t2003
> rpeat_04 rpeat_05" ;
5. * Define individual and second-level group index variables;
. local person "new_i";
6. local group "teacher_id";
7. * ******************************************************* ;
. * Set Initial Values for Individual Fixed Effects ;
. * ******************************************************* ;
. * Define initial value of each individual fixed ;
. * effect equal to average outcome for that individual ;
. bysort `person':egen initial_ife = mean(`depvar');
8. * Set initial value value of average individual effect ;
. * for group j equal to mean of initial individual;
. * fixed effects for all individuals in group j;
. bysort `group':egen initial_meanife = mean(initial_ife);
9. * ******************************************************* ;
. * Demean Variables with Respect to Teacher Averages ;
. * ******************************************************* ;
. * Determine obs. where one or more model variables are missing;
. egen nmiss = rmiss(`depvar' `expvar') ;
10. * Create demeaned dependent variable;
. bysort `group':egen Ybar = mean(`depvar') if nmiss==0;
11. gen demeanY=`depvar' - Ybar;
12. drop Ybar;
13. * Create demeaned explanatory variables;
. foreach var of local expvar {;
14. bysort `group':egen `var'_m = mean(`var') if nmiss==0;
15. gen de_`var'=`var' - `var'_m;
16. drop `var'_m;
17. };
18. * Assign macro to list of de-meaned explanatory variables;
. unab de_expvar : de_* ;
19. * ******************************************************* ;
. * Create Difference Between Demeaned Y and ;
. * Sum of Individual FE and Mean IFE ;
. * ******************************************************* ;
. gen demeanY_meanife=demeanY+initial_meanife;
20. gen demeanY_ife=demeanY_meanife-initial_ife;
21. * ******************************************************* ;
. * Initial Estimation ;
. * ******************************************************* ;
. {;
22. *Run OLS on demeaned data;
. quietly reg demeanY_ife `de_expvar', noconstant;
23. *Save coefficient estimates and;
. *initialize coefficient change at one;
. matrix old_coeff=e(b);
24. scalar coeff_dif=1;
25. *Compute predicted outcome (Xbeta);
. predict yhat ;
26. *Compute estimated individual ability for each individual/year;
. *(equals demeanedY + (average ife for group j) - (Xbeta));
. gen ufe = demeanY_meanife - yhat;
27. *Average estimated ability over all years to determine;
. *estimate of individual fixed effect;
. bysort `person':egen ife = mean(ufe);
28. *Compute average individual fixed effect for all;
. *individuals ever in group j ;
. bysort `group':egen mean_ife = mean(ife);
29. *Compute new demeanedY plus mean individual fe;
. replace demeanY_meanife=demeanY+mean_ife;
30. *Compute new demeanedY minus mean indiv. fe minus indiv. fe;
. replace demeanY_ife=demeanY_meanife-ife;
31. drop yhat ufe ife mean_ife;
32. local iter=1;
33. * ******************************************************* ;
. * Iterate Model with Peer Estimated Average Abilities ;
. * ******************************************************* ;
. * Set maximum number of iterations and tolerance;
. scalar maxiter = 1000;
34. scalar tol = 0.001;
35. * Iteratively estimate model;
. while (`iter' <= maxiter & coeff_dif > tol) {;
36. quietly reg demeanY_ife `de_expvar', noconstant;
37. matrix new_coeff=e(b);
38. matrix `bb'=e(b);
39. quietly predict yhat;
40. quietly gen ufe = demeanY_meanife - yhat;
41. quietly bysort `person':egen ife = mean(ufe);
42. quietly bysort `group':egen mean_ife = mean(ife);
43. quietly replace demeanY_meanife=demeanY+mean_ife;
44. quietly replace demeanY_ife=demeanY_meanife-ife;
45. drop yhat ufe ife mean_ife;
46. scalar coeff_dif=mreldif(new_coeff,old_coeff);
47. matrix old_coeff=new_coeff;
48. disp "Iteration " `iter';
49. disp "Maximum Coefficient Difference " coeff_dif;
50. local iter = `iter' + 1;
51. };
52. };
53. ereturn post `bb';
54. ereturn local cmd="bootstrap";
55. drop new_i;
56. end;

. bootstrap _b, reps(2) cluster(student) idcluster(new_i) seed(1234) nowarn: iterative_fe ;
(running iterative_fe on estimation sample)

Bootstrap replications (2)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
repeated time values within panel
the most likely cause for this error is misspecifying the cluster(), idcluster(), or group() option
r(451);

end of do-file
r(451);

. exit, clear


Tim R. Sass
Professor Voice: (850)644-7087
Department of Economics Fax: (850)644-4535
Florida State University E-mail: tsass@coss.fsu.edu
Tallahassee, FL 32306-2180 Internet: http://garnet.acns.fsu.edu/~tsass

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index