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

Re: st: problem with bootstrap in Stata 8.2


From   "Fabio Soares" <[email protected]>
To   [email protected]
Subject   Re: st: problem with bootstrap in Stata 8.2
Date   Mon, 19 Apr 2004 14:06:37 +0000

Dear Jeff,

Many thanks for writing down an ado file to run this dif-in-dif code using attnd command!!!!
It solved my problem!

Best wishes,

Fabio



From: [email protected] (Jeff Pitblado, StataCorp LP)
Reply-To: [email protected]
To: [email protected]
Subject: Re: st: problem with bootstrap in Stata 8.2
Date: Wed, 14 Apr 2004 16:42:22 -0500

Fabio Soares <[email protected]> is having trouble with the -bootstrap-
command and a user written program:

> I�m running a difference-in-difference propensity score program using logit
> and attnd commands and I didn�t manage to get the bootstrapped s.e. using
> the bootstrap command. Does anyone spot any mistake in the following code:
>
> capture program drop difatt
> program define difatt, rclass
>
> use favbar9100, clear
> drop if bairrinho==1 | nurb==1
>
> xi: logit fb dom91 agua91 esg91 lixo91 escm4_91 escm15_91 analf91 /*
> */ menor4_91 chmul91 up1sm_91 /*
> */ nmor91 mul91 chanalf91 amest_91 idade_91 ren_91
> i.RA
>
> predict pscore
>
> attnd rren_00 fb, pscore(pscore)
> scalar return difren00=r(attnd)
>
> attnd rren_91 fb, pscore(pscore)
> scalar return difren91=r(attnd)
>
> scalar return difren=r(difren00) - r(difren91)
>
> end
>
>
> bootstrap "difatt" difren=r(difren), reps(100)

Here are a few things I spotted:

1. If -bootstrap- is going to call -difatt-, -difatt- should not -use-
another dataset for analysis. It is -bootstrap-'s job to provide a
dataset for -difatt- to compute its results from.

2. -xi- should not be used within -difatt-. Similar to -use-,
generate the -xi- variables before calling -bootstrap-.

3. -rclass- commands return scalars using -return scalar- (not -scalar
return-).

Given the above comments, and to make -difatt- usable with other datasets,
here is another version of -difatt-:

*** BEGIN: difatt.ado
program define difatt, rclass
version 8.2
syntax varlist, OUTCOME1(varname) OUTCOME2(varname)

// identify the dependent variable
gettoken depvar : varlist

// fit a logit model
logit `varlist'

// generate the -pscore-
tempvar pscore
predict `pscore'

// compute -attnd- for -outcome1-
attnd `outcome1' `depvar', pscore(`pscore')
return scalar attnd1 = r(attnd)

// compute -attnd- for -outcome2-
attnd `outcome2' `depvar', pscore(`pscore')
return scalar attnd2 = r(attnd)

// compute the difference
return scalar difatt = return(attnd1) - return(attnd2)
end
*** END: difatt.ado

Here is a small do-file using the auto data to illustrate how to use -difatt-
with -bootstrap- and -xi-:

***** BEGIN:
clear
sysuse auto

// generate some outcome vars for -attnd- calls within -difatt-
gen xx1 = uniform() < .3
gen xx2 = uniform() < .4

// generate some indicator variables
xi i.rep

// example of -difatt-'s new syntax
difatt for mpg turn _Irep78*, outcome1(xx1) outcome2(xx2)
di "r(difatt) = " r(difatt)

// bootstrap the result from -difatt-
bootstrap "difatt for mpg turn _Irep78*, outcome1(xx1) outcome2(xx2)" r(difatt)
***** END:

Give the new -difatt-, Fabio's do-file will look something like:

***** BEGIN: Fabio's do-file
// ... -- previous setup to read in data
xi i.RA
local xvars dom91 agua91 esg91 lixo91 escm4_91 escm15_91 analf91 ///
menor4_91 chmul91 up1sm_91 nmor91 mul91 chanalf91 amest_91 ///
idade_91 ren_91 _IRA*
bootstrap "difatt fb `xvars', outcome1(difren00) outcome2(difren91)" r(difatt)
***** END: Fabio's do-file

--Jeff
[email protected]
*
* 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/
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection http://www.msn.co.uk/specials/btbroadband

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index