Announcement

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

  • Problem with stars in creating a table using collect

    Hi,

    I am having problems creating a table output using Stata new command "collect".

    in particular, I am having a hard time being able to apply stars (related to statistical significance) in a table where I estimate two models and I perform 3 tests for each model.
    what I need to do is to have a table with stars for each of the three tests (in 3 rows), that are performed for each model (in 2 columns).

    when I use the command "collect stars..." then I am only able to have stars on the third test and not on the previous two. I am aware I am missing something here.

    I include an example with a fake model, any help would be appreciated!

    John


    ************************ FAKE MODEL EXAMPLE:


    use https://www.stata-press.com/data/r17/nhanes2l, clear


    * program that produces the scalars to be put in table
    capture program drop coeffint
    program define coeffint, rclass

    *test if effect of protestant minority different from catholic minority

    return scalar observations =e(N)
    return scalar erredue =e(r2)

    lincom weight + 1.sex
    return scalar diff1 = r(estimate)
    return scalar serr1 = r(se)
    return scalar pval1 = ttail(r(df),abs(r(estimate)/r(se)))*2

    lincom weight + 1.agegrp
    return scalar diff2 = r(estimate)
    return scalar serr2 = r(se)
    return scalar pval2 = ttail(r(df),abs(r(estimate)/r(se)))*2


    lincom weight + 1.race
    return scalar diff3 = r(estimate)
    return scalar serr3 = r(se)
    return scalar pval3 = ttail(r(df),abs(r(estimate)/r(se)))*2


    end

    * create collection
    collect clear
    collect create MyModels

    * first regression and collection
    regress bpsystol weight i.sex i.agegrp i.race height weight

    coeffint

    collect get ESTM1=r(diff1) STDER1=r(serr1) PVAL1=r(pval1) ESTM2=r(diff2) STDER2=r(serr2) PVAL2=r(pval2) ESTM3=r(diff3) STDER3=r(serr3) PVAL3=r(pval3) OBSVT=r(observations) ERRE2=r(erredue), name(MyModels) tag(model[(1)])

    * second regression and collection
    regress bpsystol weight i.sex i.agegrp i.race height hgb i.hlthstat i.location

    coeffint

    collect get ESTM1=r(diff1) STDER1=r(serr1) PVAL1=r(pval1) ESTM2=r(diff2) STDER2=r(serr2) PVAL2=r(pval2) ESTM3=r(diff3) STDER3=r(serr3) PVAL3=r(pval3) OBSVT=r(observations) ERRE2=r(erredue), name(MyModels) tag(model[(2)])

    * create labels
    collect label values result ESTM1 "000" ESTM2 "012" ESTM3 "014" OBSVT "Obs." ERRE2 "R2", modify
    * hide labels se
    collect style header result[STDER1 STDER2 STDER3], level(hide)
    * parenthesis se
    collect style cell result[STDER1 STDER2 STDER3], sformat((%s))
    * format values
    collect style cell result[ESTM1 STDER1 ESTM2 STDER2 ESTM3 STDER3 ERRE2], nformat(%8.3f)
    *title
    collect title "Table title here"

    * i would like to put stars attached to each of the 3 rows' statistics, but this only works for the third statistics
    collect stars PVAL1 0.01 "***" 0.05 "**" 0.1 "*", attach(ESTM1) shownote
    collect stars PVAL2 0.01 "***" 0.05 "**" 0.1 "*", attach(ESTM2) shownote
    collect stars PVAL3 0.01 "***" 0.05 "**" 0.1 "*", attach(ESTM3) shownote


    collect layout (result[ESTM1 STDER1 ESTM2 STDER2 ESTM3 STDER3 OBSVT ERRE2]) (model)

Working...
X