Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: resampling issue


From   "Steve Stillman" <[email protected]>
To   <[email protected]>
Subject   st: RE: resampling issue
Date   Sat, 1 Jul 2006 01:31:16 +1200

Pradeep.  One approach is to prefix the probit command (I assume this is
where you program is crashing) with capture (eg 'capture probit foreign
weight mpg') and then add the line 'if _rc~=0 { continue }' following
the probit command.  This will send your program back to the beginning
of the loop whenever the probit command fails.  The only thing it won't
do is reset the counter, thus you will end up with (20-failed)
resamples.  There may be some clever way to do this as well.

Hope this helps,
Steve

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Pradeep
Kurukulasuriya
Sent: Thursday, June 29, 2006 1:21 AM
To: [email protected]
Subject: st: resampling issue


I am trying to use a forvalues loop to resample observations and run 3
equations (for each draw): a probit followed by 2 OLS models.  The
problem I
am facing is that, it works sometimes, but all the time. The reason is
when
stata selects a sample of, say 20 observations (from a set of 70), in
certain draws there are insufficient observations to run a probit and
the 2
OLS models that follow. I would like to know if someone can help me
overcome
this issue. Basically, can STATA be instructed to resample if there are
insufficient observations to run the probit AND the two conditional OLS
models and repeat X number of times?

Would be most grateful for any help. The program below recreates a
problem I
am facing.

sysuse auto, clear
tab foreign, nolabel
gen colvar = price + mpg + .2*uniform()
gen newprice= price* .2*uniform()
gen forprice=newprice if foreign==1
gen domprice=newprice if foreign==0
gen c_weight=.
gen c_mpg=.
gen c__cons=.
save test, replace
drop c_*
save auto2, replace

forvalues i = 1/20 {
drop _all
use test, clear
bsample 20

    sum foreign
    if r(sd)>0 {
    probit foreign weight mpg
 	matrix b=e(b)
 	matrix list b
 	** Create macro containing list of valid regressors **
 	local names  : colnames b
 	di "`names'"
 	foreach variabs in `names' {
 	replace c_`variabs'=_b[`variabs']
 	replace c_`variabs'=0 if c_`variabs'==.
 	}
      /*rest of commands in your loop*/

 	gen xb0_`i'=c_weight*weight + c_mpg*mpg +c__cons
       gen prob`i'=norm(xb0_`i')

 	/*estimating Inv Mills Ratio*/
 	gen phi0_`i'=(1/sqrt(2*_pi))*exp(-(xb0_`i'^2/2))
 	gen  capphi0_`i'=norm(xb0_`i')
 	gen  invmills0_`i'=phi0_`i'/capphi0_`i'

      regress forprice mpg weight invmills0_`i'
      regress domprice mpg weight invmills0_`i'
    }
    else {
      /*drop variables and start next loop*/
      drop turn
      di "dropped turn"
    }
}

*
*   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/


*
*   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