Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Program syntax for svy bootstrap or bs4rw

From   Jeffrey Pitblado <>
Subject   Re: st: Program syntax for svy bootstrap or bs4rw
Date   Tue, 26 Jun 2012 11:11:22 -0500

Mark McGovern<> asked a question about programming
syntax and using -svy bootstrap- or my -bs4rw- prefix command. Stas Kolenikov
and Steve Samuels replied with several good suggestions, but Mark is still
having some trouble:

Thank you Steve and Stas for your suggestions. For now I can work with
bs4rw, although at some point I think I might need to use some of the
functionality of svy, so I may have to return to this in the future.

As you pointed out Steve, from the Stata 12 programming manual (p.326):

1. Command must be eclass and allow iweights and accept the standard
estimation syntax.
2. Command must save the model coefficients and ancillary parameters
in e(b) and the estimation sample size in e(N), and it must identify
the estimation subsample in e(sample);
3. svy’s vce(bootstrap), vce(brr), and vce(sdr) require that command
have svyb as a property.

I thought these were satisfied as the original code below does return
results in e() in the usual way from "regress". For example,
specifically overwriting e() does not help as in the below.

Here is Mark's code:

capture program drop test1
program define test1, eclass properties(svyb)
        syntax [if] [in] [pw iw]
        marksample touse
        tempvar b V
        qui xi:reg age race [`weight'`exp'] if `touse'
        capture drop re1
        predict re1
        qui xi:reg birthwgt re1 [`weight'`exp'] if `touse'
        local nobs = e(N)
        matrix `b' = e(b)
        matrix `V' = e(V)
        ereturn post `b' `V', esample(`touse')
        ereturn local cmd="test1"
        ereturn scalar N = `nobs'
        ereturn display

svy : test1

The problem here is that

	. svy : test1

looks like a replay call to -svy-.  Mark put all the model specfication
information in the -test1- program.  Mark can add something to the syntax
to -test1- that will prevent -svy- from trying to replay nonexistent results.
I would suggest

	. svy : test1 in 1/l

-- Jeff Pitblado

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index