Announcement

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

  • Obtain very different results using -xtreg- and -margins- / can I store the results from -margins- in a table

    When I run the interaction between a dummy (0/1) variable (at3) and a categorical variable (vtype), the results from -xtreg- are very different to those from -margins-. I would like to know:

    1) Why are the results from -xtreg- and -margins- so different?

    2) is there a way to combine the results from -margins- to create a table using -esttab- or some other command?

    The following code only creates a table of estimates obtained from -xtreg-:
    Code:
    xtreg c.finr i.at3##i.vtype
    margins i.faith2##i.at3
    estimates store s1
    
    xtreg c.nonfinr i.at3##i.vtype
    margins i.faith2##i.at3
    estimates store s2
    
    xtreg c.assetr i.at3##i.vtype
    margins i.faith2##i.at3
    estimates store s3
    
    xtreg c.debt i.at3##i.vtype
    margins i.faith2##i.at3
    estimates store s4
    
    xtreg c.wealth2r i.at3##i.vtype
    margins i.faith2##i.at3
    estimates store s5
    
    esttab s1 s2 s3 s4 s5 using interactions.rtf, b(%10.0fc) star(* 0.10 ** 0.05 *** 0.01) varwidth(35) not nogaps label stats(N r2) ///
    compress replace nonumbers title("Interaction effects" ) mtitle("""")
    I'm unable to provide an example at the moment but can do later if needed.

    Stata v.15.1. Using panel data.
    Last edited by Chris Boulis; 29 Jul 2021, 21:33.

  • #2
    UPDATE:

    My apologies, there were inconsistencies in my code in #1. Here's updated/briefer code. -margins- would not allow me to include the continuous variables as in -xtreg- so I dropped the continuous variable at the beginning of the regression and simply ran the interaction using margins directly after running -xtreg- (as below). Is that correct?
    Code:
    xtreg c.finr i.at3##i.vtype 
    margins i.vtype ##i.at3
    estimates store s1
    
    xtreg c.nonfinr i.at3##i.vtype 
    margins i.vtype ##i.at3
    estimates store s2
    
    xtreg c.wealth2r i.at3##i.faith2
    margins i.vtype ##i.at3
    estimates store s3
    
    esttab s1 s2 s3 s4 s5 using interactions.rtf, b(%10.0fc) star(* 0.10 ** 0.05 *** 0.01) varwidth(35) not nogaps label stats(N r2) /// incl ',' each ,000
    compress replace nonumbers title("The interaction effect of religion and attendance" )
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(finr nonfinr wealth2r) byte(at3 vtype)
     348284.4 1154489.4 1421375.6 0 1
     45616.11  7109.005  15995.26 0 1
     389017.8 1126777.3   1116506 0 1
    154620.86 2375592.5 2014810.5 0 1
    2325.8293  20142.18 13550.948 0 1
     388112.6  947867.3  885742.9 0 1
     388151.7   1186019 1011374.4 0 1
     105632.7 267772.53  349708.5 0 1
     76066.35 17772.512  91232.23 0 1
     174881.5   1271327  844549.8 0 1
     48129.15  8293.839  24669.43 0 1
     12796.21  335308.1  282938.4 0 1
    12417.062 131753.56 110995.27 0 1
      9644.55 609004.75  618649.3 0 1
    74407.586  379181.3 262830.56 0 1
      99539.1 196682.47 268377.97 0 1
    151978.67  841232.3  637760.7 0 1
    21682.465  39099.53 34597.156 0 1
     703909.9 592417.06   1296327 0 1
     452473.9   20734.6  435354.3 0 1
     582984.6  947867.3 1056918.3 0 1
     93253.55 611374.44  63221.57 0 1
     78199.05  159952.6  135071.1 0 1
     631516.6 584123.25 1215639.9 0 1
    35582.938 23696.684 23260.664 0 1
     910545.1 599526.06 1273104.3 0 1
      1557544 1398104.3   2937876 0 1
      4034.36  5924.171   8181.28 0 1
    32109.006  722748.8  285047.4 0 1
     56872.04 1504739.4  832938.4 0 1
    232760.67  582938.4  486907.6 0 1
     829383.9  473933.7 1300876.8 0 1
     190639.8 148104.27  338744.1 0 1
    202606.64 1167061.6  963270.2 0 1
    1882.7014 4146.9194  5887.441 0 1
     73696.69  71090.05  112796.2 0 1
    14241.706 469786.75 186042.66 0 1
      1889467 622037.94   2487808 0 1
    246552.14  627962.1  756030.8 0 1
    1857373.3 1646919.5   3166615 0 1
    292654.03    714455  817535.6 0 1
    1945497.6 1145142.3   3090640 0 1
     230951.4  53317.54  256069.9 0 1
     25355.45 15402.844 34241.707 0 1
     21674.17  50947.87 16934.834 0 1
     795142.2 1267772.5 2062914.8 0 1
     243259.5  98341.23 287098.34 0 1
    end

    Comment


    • #3
      Hi Chris
      For the first question.
      The way you are calling on margins is NOT to provide marginal effects (those are requested using a syntax like : margins, dydx(variables)
      What you are obtaining are the marginal means. Or, the expected value of the outcome for specific combinations of the categorical variables.

      For the second.
      You need to add the option "post" after margin, so it stores the table into something you can store using "est store"
      HTH
      F

      Comment


      • #4
        Thank you FernandoRios for your advice. To clarify - after running
        Code:
        xtreg c.finr i.at3##ib2.vtype
        , I run, e.g."margins, dydx(at3 vtype)" will give me the marginal effects of each category of vtype with respect to at3 (0/1) when at3 == 1? with respect to "fin" (financial assets)? These results differ to those running "margins at3##ib2.vtype", in that the latter will give the full effect (the main and interaction effect) whereas the former gives the marginal effect only? I'm a bit unclear how to interpret the different results of these two options using margins.
        Last edited by Chris Boulis; 31 Jul 2021, 20:40.

        Comment


        • #5
          when you use "margins", the command produces how the outcome would change from the base category (usually 0) to the one of interest (at=1) in average. Same for vtype. How it changes from the base (b2 ) to the one observed.

          Your second syntax estimates the average outcome, for each sub group

          At this point the question is. What is it you want to discuss? how things change at the margin, or how the outcome differs for different groups.

          Comment

          Working...
          X