Announcement

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

  • Save margin pwcompare

    Hi all,

    I'd like to save margins pairwise comparisons (contrast, standard error and p-value) in locals. However, from the matrix of results, I can only retrieve the contrast. Does anyone know if it's feasible?

    Thank you

    Code:
    sysuse auto.dta
    set seed 20210604
    gen random=runiform()
    sort foreign random
    gen foreign2=0 in 1/26
    replace foreign2=1 in 27/52
    replace foreign2=2 if missing(foreign2)
    gen rep78_2=cond(inrange(rep78, 4, 5), 1, cond(inrange(rep78, 1, 3), 0, .))
    regress price i.foreign2#i.rep78_2 mpg
    margins i.foreign2#i.rep78_2, pwcompare(pveffects)
    mat b=r(table)
    mat li b

  • #2
    https://www.statalist.org/forums/for...th-interaction #2

    Comment


    • #3
      Thanks Andrew Musau, this is very useful.

      I'm trying to save the p-value separately to compute sharpened FDR q-values, and the standard errors for another purpose and would ideally like to save them as locals. Do you know whether there is a way?

      Below is the result I am trying to export.

      Thank you for your help

      Code:
      sysuse auto.dta, clear
      set seed 20210604
      gen random=runiform()
      sort foreign random
      gen foreign2=0 in 1/26
      replace foreign2=1 in 27/52
      replace foreign2=2 if missing(foreign2)
      gen rep78_2=cond(inrange(rep78, 4, 5), 1, cond(inrange(rep78, 1, 3), 0, .))
      regress price i.foreign2##i.rep78_2 mpg
      
      margins, at(foreign2=(1 2) rep78_2=0) pwcompare(pveffects)
      /*
      -----------------------------------------------------
                   |            Delta-method    Unadjusted
                   |   Contrast   Std. Err.      t    P>|t|
      -------------+---------------------------------------
               _at |
           2 vs 1  |  -871.8891   1625.997    -0.54   0.594
      -----------------------------------------------------
      */
      * Looking to save in locals the contrast, std. error and p-value for "(2 0) vs (1 0)"
      
      * coefficient
      mat b=e(b)
      local b1= b[1,2]
      local b2= b[1,3]
      local b=`b2'-`b1'
      display "b1=`b1', b2=`b2', b=`b'"

      Comment


      • #4
        All good - margins has an undocumented saving() option

        Comment


        • #5
          The required information is also available in r(table_vs).

          Comment


          • #6
            Perfect, thank you daniel klein

            Comment

            Working...
            X