Statalist The Stata Listserver

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

st: resampling issue

From   "Pradeep Kurukulasuriya" <>
To   <>
Subject   st: resampling issue
Date   Wed, 28 Jun 2006 09:20:51 -0400

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:

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