Announcement

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

  • How to concatenate parameters from two -nlcom- commands into one estimation result using -estadd- or... in a program that I will bootstrap?

    I am using nlcom to compute adjusted relative risks and adjusted risk differences following -margins- after a logistic regression GEE model. One nlcom postestimation has several factor variables. The second postestimation computes an effect for age, which I evaluate at age 45 and 55, so must run in a separate margins command from the factor variables, which I do not want evaluated at particular ages. It is easy enough to make two nlcom commands, but I am bootstrapping and want to bootstrap all the parameters at once rather than have to bootstrap twice. I am trying to figure out how to combine or concatenate the nlcom results into one estimation result.

    I have tried different approaches with -estadd- with no success including specifying the estimates from one of the nlcoms as a matrix or scalar or writing a new estadd subcommand program (like estadd_mysubcommand at the end of the help file). Here, I simplify the code with only one factor variable for brevity.


    capture program drop bootstrap
    program define bootstrap, eclass
    xtset new_cluster
    xtgee y i.b age_10 , ///
    corr(exch) family(binomial) link(logit) vce(robust)
    est sto boots
    margins b, post
    nlcom (rr_b:_b[2.b]/_b[1.b]) (rd_b:_b[2.b]-_b[1.b]) , post
    est sto boots_fx
    est res boots
    margins , at(age_10=(4.5 5.5)) post coeflegend
    nlcom (rr_age5545:_b[2._at]/_b[1._at]) (rd_age5545:_b[2._at]-_b[1._at]), post coeflegend
    est sto boots_age
    estadd :boots_fx *I know this doesn't work
    end

    bootstrap (rr_b:_b[rr_b]) (rr_age5545:_b[rr_age5545]) (rd_b:_b[rd_b]) (rd_age5545:_b[rd_age5545]), reps(10) seed(12345) cluster(cluster) ///
    idcluster(new_cluster) group(studyid) : bootstrap
    estat bootstrap, all

    Thanks!

  • #2
    I figured it out using matrices, key changes bolded.

    capture program drop bootstrap
    program define bootstrap, eclass
    xtset new_cluster
    xtgee y i.b age_10 , ///
    corr(exch) family(binomial) link(logit) vce(robust)
    est sto boots
    margins b, post
    nlcom (rr_b:_b[2.b]/_b[1.b]) (rd_b:_b[2.b]-_b[1.b]) , post
    matrix boots_fx = e(b)
    est res boots
    margins , at(age_10=(4.5 5.5)) post coeflegend
    nlcom (rr_age5545:_b[2._at]/_b[1._at]) (rd_age5545:_b[2._at]-_b[1._at]), post coeflegend
    matrix boots_age = e(b)
    matrix boots = (boots_fx,boots_age)
    ereturn post boots

    end
    Last edited by Alex Woersching; 23 Apr 2017, 12:47.

    Comment

    Working...
    X