Bookmark and Share

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


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

Re: st: bootstrapping results from more than one command


From   Stas Kolenikov <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: bootstrapping results from more than one command
Date   Tue, 4 Jan 2011 09:10:12 -0600

Terve,

Kaisa Kotakorpi wants to collect the results of several estimation
commands for the bootstrap purposes:

On Tue, Jan 4, 2011 at 7:44 AM, Kaisa Kotakorpi <kaisa.kotakorpi@uta.fi> wrote:
> I'm trying to do the following: We are estimating a system of 8 demand
> equations (QUAIDS), out of which we get 64 price elasticities for 18 000
> households. We want bootstrapped estimates for the weighted averages  of
> each of these 64 elasticities. We have written a programme that (i)
> estimates the demand system; (ii) calculates the household-specific
> elasticities and (iii) calculates the weighted averages of these
> elasticities. At the end of the programme, we would thus have a separate
> "mean" command (with option pweight) for each elasticity. (We cannot run
> these within one "mean"-command, as we require different weights for each
> mean; if we could use the same weights, we could estimate all means on one
> line, in which case we would be able to produce them all at once).
>
> However, bootstrapping this programme will produce only what is in the e()
> at the end of the programme, i.e. we will only get the last one of the 64
> mean elasticities. Is there a way to store the rest of the elasticities, and
> get them bootstrapped also? (What we really want repeated is the demand
> system estimation, and all 64 elasticities follow from this.)

I will write pseudo-Stata code to provide you some ideas. You need to
fill in the details before it runs at all. Given that you've coded a
sizeable project, I assume you'd be able to do that. Note that if you
have panel or clustered data (and I imagine you do, as you utilize
some weight manipulation, although of course you may have something
reasonably close to SRS from your population register), you need to
use special forms of the bootstrap, as described in my SJ 10(2) paper
(-findit bsweights-). The plain vanilla -bootstrap- will give standard
errors that will be too small by double digit per cent. If that is the
case, you would also need to parse the weights and pass them to your
estimation commands.

Option 1: r() results and locals

local explist
forvalues k=1/64 {
  local explist `explist' (el`k' : r(el`k') )
}

program define Wrapper1, rclass
   EstimateDemandSystem
   forvalues k=1/64 {
      CalculateElasticity `k'
      return el`k' = (calculated `k'-th elasticity)
   }
end
* of Wrapper 1

bootstrap `explist' : Wrapper1

Option 2: e() results; note that this is not a proper estimation
command, but just a wrapper to supply the -bootstrap- with what it
needs.

program define Wrapper2, eclass
   EstimateDemandSystem
   tempname b
   forvalues k=1/64 {
       CalculateElasticity `k'
       if `k' == 1 {
          matrix `b' = calculated `k'-th elasticity
       }
       else {
          matrix `b' = `b', calculated `k'-th elasticity
       }
   }
   ereturn post `b'
   ereturn local cmd Wrapper2
   * this is the convention for eclass commands, see [P] ereturn
end
* of Wrapper2

bootstrap : Wrapper2

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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