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

st: bootstrap and singleton


From   "R.E. De Hoyos" <redeho@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: bootstrap and singleton
Date   Mon, 2 May 2005 21:02:27 +0100

Statalist,

I am trying to get bootstrapped SE from estimates that control for survey design. I am using the
-bsample- command with the strata() option. Since I have some singleton strata, after every re-sampling I temporary delete the singleton strata. However when using my code I (sometimes) get the singleton error. I've been going to my code using -set trace on- command but I cannot see anything wrong with it. When the error occurs it is just after the _robust estimation withing -svy- takes place.

Any thoughts?

Many thanks,

Rafa
PS. I include part of the code:

syntax varlist [if] [in], SELect(string) [SHOWmlogit BOOTstrap(string) MLOPtions(string)]

tokenize `varlist'

local y `1'

tokenize `bootstrap', parse(" ")

local K `1'

tempvar singleton

tokenize `select', parse("=")

local m `1'

macro shift

local z `2'

qui svyset

singleton `varlist' `z', strata(`r(strata)') gen(`singleton') //programme to identify singleton

if "`bootstrap'"=="" {

qui sum `singleton'

if `r(max)' == 0 {

base `varlist' `if' `in', select(`select') `showmlogit' mloptions(`mloptions')

}

else {

preserve

qui drop if `singleton'==1

noi di in yellow "`r(sum)' strata with single PSU detected and excluded from the estimation"

base `varlist' `if' `in', select(`select') `showmlogit' mloptions(`mloptions')

restore

}

}

else {

tempname b bstrv

local k=1

while `k'<=`K' {

preserve

qui svyset

bsample, strata(`r(strata)')

tempvar singleton`k'

tokenize `select', parse("=")

macro shift

local z `2'

qui svyset

singleton `varlist' `z', strata(`r(strata)') gen(`singleton`k'')

drop if `singleton`k'' == 1

base `varlist' `if' `in', select(`select') bootstrap mloptions(`mloptions')

tempname b`k'

matrix `b`k''=e(b)

if `k'==1 {

matrix `b'=`b`k''

}

if `k'>1 {

matrix `b'=`b'+`b`k''

}

restore

local k=`k'+1

}

local k=1

while `k'<=`K' {

if `k'==1 {

matrix `bstrv'=(`b`k'' - (`b'/`K'))'*(`b`k'' - (`b'/`K'))

}

if `k'>1 {

matrix `bstrv'=`bstrv'+(`b`k'' - (`b'/`K'))'*(`b`k'' - (`b'/`K'))

}

local k=`k'+1

}

matrix `bstrv'=`bstrv'/(`K'-1)
*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index