Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Estimates store, e(cmd) and bootstrap

    Dear Statalist,

    I have a weird combination of problems. I'm writing a small program for computing the earnings penalties associated with first child birth for women and men. The parameters of interest is constructed as nonlinear combinations of regression parameters, and I want my program to work with bootstrap to compute bootstrapped standard errors and to use the delta method (using nlcom). In addition, it would be nice to have the program fast and efficiently spit out the parameters without standard errors. The problem is the following
    • It is not possible to store an estimate with estimates store unless the program returns e(cmd): "Last estimation result not found, nothing to store". Works fine with the user written eststo
    • If returning e(cmd), I cannot bootstrap using the program. Bootstrap complains "varlist required". It has to do with the bootstrap display following the repetitions, and looks like a conflict between bootstrap setting e(cmd) and e(cmdline) and my program doing the same.
    The MWE below illustrates the proble. There's probably some really stupid thing I don't get. I could always make two separate options, one for not computing the V matrix and another one for not reporting e(cmd), but it seems like a struggle for the user to remember how to combine these two options correctly. There must be some straightforward solution here - any help appreciated. Thanks!

    Code:
    cap program drop testcmd
    {
    prog define testcmd, eclass 
    version 15.0
    syntax varname [, cmd]
    
    qui proportion `varlist'
    mat b=e(b)
    mat V=e(V)
    
    if "`cmd'"=="" ereturn post b V
    else ereturn post b
    ereturn local cmdline "testcmd `0'"
    if "`cmd'"!="" ereturn local cmd "testcmd"
    ereturn di
    end
    }
    
    sysuse auto, clear
    
    testcmd rep78
    est sto nocmd ///Does not work because e(cmd) not set
    testcmd rep78, cmd
    est sto nocmd ///Works fine
    
    bootstrap, reps(2): testcmd rep78, cmd
    est sto bootcmd /// Does not work, some conflict with bootstrap setting e(cmd)
    bootstrap, reps(2): testcmd rep78
    est sto bootnocmd /// Works fine
Working...
X