Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: From: David Jose <[email protected]>
From
Richard Goldstein <[email protected]>
To
[email protected]
Subject
Re: st: From: David Jose <[email protected]>
Date
Fri, 29 Mar 2013 10:21:33 -0400
Hi David,
a while ago I send approximately this question to StataCorp and Isabel
Cannette drafted some code (not tested) for me; my project then changed
and I did not test her code or revise it for my circumstances; I am
sending this with her permission; I note that her code is based on A.
Colin Cameron, Jonah B. Gelbach, and Douglas L. Miller (2008),
"BOOTSTRAP-BASED IMPROVEMENTS FOR INFERENCE WITH CLUSTERED ERRORS", The
Review of Economics and Statistics, 90(3): 414-427 (and I had pointed
her specifically to appendix B in that article)
good luck,
Rich
Here is the code: (watch for wrapped lines; you can identify such a line
if the first character on the left is not a ">"; if any, join that line
to the end of the preceding line)
> *Let's assume that we have the regression
>
> cscript
> sysuse auto
> drop if rep == .
> regress mpg disp turn, cluster(rep)
>
> *and the null hypothesis H0: _b[displacement] = 0.1
>
> ***********
> * Step 1: *
> ***********
> *Step 1-1) Compute w (if my t_0 was 0, it would be the t from the
table).
>
> regress mpg disp turn, cluster(rep)
> local w = (_b[displacement] - .1)/ _se[displacement]
> di "`w'"
>
> *Step 1-2) fit the restrained constraint
>
> constraint 1 displacement = .1
> cnsreg mpg disp turn, constraint(1)
> mat bR = e(b)
> predict uR , residuals
> predict xbR, xb
> *I have one long vector of residuals uR
> *I also have the restricted linear prediction xbR
>
>
>
> ************
> * Step 2a: *
> ************
> *Form a sample of clusters
>
> *Step 2a-1: generate the weights a_g, which are unique to each
> *cluster
>
> sort rep
> gen ag = cond(runiform()<.5, -1, 1)
> by rep: replace ag = ag[1]
> list rep ag, sepby(rep)
>
> *setp 2a-2: generate uRstar
> gen uRstar = uR*ag
>
> *step 2a-3: generate yhatstar
> gen yhatstar = xbR + uRstar
>
> ***********
> * Step 2b: *
> ***********
> *compute wstar, the same way as in step 1, but using yhatstar
> *instead of y (mpg).
>
> regress yhatstar disp turn, cluster(rep)
> local wstar = (_b[displacement] - .1)/ _se[displacement]
>
>
> ***********
> * Step 3 *
> ***********
>
> *I need to repeat the previous process B times (you can check
> *if there is a recommended number of replications in the article)
> *I will use B = 100
>
> program getwstar, rclass
> *I am using external variables rep, uR, xbR, disp and turn
> tempvar ag uRstar yhatstar
> gen `ag' = cond(runiform()<.5, -1, 1)
> bysort rep: replace `ag' = `ag'[1]
>
> gen `uRstar' = uR*`ag'
> gen `yhatstar' = xbR + `uRstar'
> regress `yhatstar' disp turn, cluster(rep)
> return scalar wstar = (_b[displacement] - .1)/ _se[displacement]
> end
>
> getwstar
> return list
>
> *now I need to get the 100 values of wstar, and compare w with
> *quantiles of wstar.
>
> simulate wstar = r(wstar), reps(100) saving(wstar_file, replace):
getwstar
> use wstar_file, clear
>
> _pctile wstar, p(2.5, 97.5)
> return list
>
> display `w'
>
> if (`w'<r(r1))| `w'> r(r2){
> local mytest "Reject H0"
> }
> else{
> local mytest "Don't reject H0"
> }
>
> display "******** `mytest' **********"
On 3/28/13 8:19 AM, [email protected] wrote:
> Hi all,
>
> I'd like to implement a stata routine that computes SEs based on a
> "wild cluster bootsrap" procedure (Cameron, Gelbach, Miller (ReStat
> 2008)).
>
> Any ideas?
>
> I have found a procedure here http://www.ifs.org.uk/publications/6231,
> but it does not compute SEs, but rather only p values.
>
> Thanks in advance for any help!
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/