Announcement

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

  • Include labels after margins pwcompare matrix

    First time poster. Apologies for errors. I'm wondering if there's a way to grab the labels along with the pairwise comparisons table? In the code below, I can get the table easily enough but I can't seem to get the labels with it. Ideally, I'd like the matrix to be labeled the same way the actual output is. I have to repeat this many times, however, so it's not feasible to copy and paste directly from Stata's output window into the .rtf created by esttab.

    Code:
    sysuse auto, clear
    foreach var of varlist price mpg rep78 {
         egen `var'dummy = cut(`var'), group(2)
         label def `var'dummy 0 "Below Avg. `var'" 1 "Above Avg. `var'"
         label val `var'dummy `var'dummy
    }
    logit pricedummy i.mpgdummy##i.rep78dummy headroom trunk weight
    margins mpgdummy##rep78dummy, pwcompare(pv) atmeans post
    matselrc r(table_vs) a, r(1 2 4)
    mat li a
    esttab mat(a, transpose fmt(%9.2f)) using pwdiffs.rtf, replace

  • #2
    FYI: Solved with help of Stata technical support:

    Code:
    // Run logit model
    sysuse auto, clear
    foreach var of varlist price mpg rep78 {
        egen `var'dummy = cut(`var'), group(2)
        label def `var'dummy 0 "Below Avg. `var'" 1 "Above Avg. `var'"
        label val `var'dummy `var'dummy
    }
    logit pricedummy i.mpgdummy##i.rep78dummy headroom trunk weight
    
    // Set formatting during the call to -margins-
    margins mpgdummy##rep78dummy, pwcompare(pv) atmeans post ///
           cformat(%9.2f) sformat(%8.2f) pformat(%5.2f)
    
    // Clear the putdocx buffer (just in case) and begin
    putdocx clear
    putdocx begin
    
    // Export the table using -putdocx-, but drop column 4 (z-score)
    putdocx table pairwise = etable
    putdocx table pairwise(.,4), drop
    
    // Write the document to a file
    putdocx save pwdiffs.docx , replace

    Comment

    Working...
    X