Announcement

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

  • Illustrating cross country linear and interaction effects

    Hello,
    I'm trying to illustrate both a linear and an interaction effect across countries using fixed effects, something resembling these two figues from Richardson (2021).
    Click image for larger version

Name:	Richardson 2021.PNG
Views:	1
Size:	144.6 KB
ID:	1648891


    Any ideas how this can be done based on my regression estimates?

    Best regards

  • #2
    Christian:
    see -margins- and -marginsplot-.
    As an aside, sponsored by the FAQ, full reference, please. Thanks.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Hi Carlo,
      I creating a marginsplot using the following code:
      Code:
      xtset essround
      xtreg c.yvar i.xvar i.controls c.controls i.cntry2, robust fe
      margins cntry2
      marginsplot, recast(scatter) ytitle(Intolerance) xtitle("") xlabel(, angle(20)) title("") scheme(s1mono) note("95 % confindence interval based on maximum likelihood")
      which created this graph where 1) effectsizes corresponding to countries can't be interpreted 2) effects are not ordered after effects:
      Click image for larger version

Name:	1.PNG
Views:	1
Size:	42.8 KB
ID:	1649073



      EDIT: Full reference:
      Richardson, Thomas. “Height Is Associated with More Self-Serving Beliefs About Wealth Redistribution.” Evolution and human behavior 42.4 (2021): 287–294. Web.

      Comment


      • #4
        Christian:
        I do hope the what follows can be helpful:
        Code:
        . use https://www.stata-press.com/data/r17/auto
        (1978 automobile data)
        
        . generate tons = weight/2000
        
        . format tons %6.2f
        
        . separate mpg, by(foreign)
        
        Variable      Storage   Display    Value
            name         type    format    label      Variable label
        ----------------------------------------------------------------------------------------------------------------------------------------
        mpg0            byte    %8.0g                 mpg, foreign == Domestic
        mpg1            byte    %8.0g                 mpg, foreign == Foreign
        
        
        . regress mpg foreign##c.tons##c.tons
        
              Source |       SS           df       MS      Number of obs   =        74
        -------------+----------------------------------   F(5, 68)        =     31.82
               Model |   1711.8059         5  342.361181   Prob > F        =    0.0000
            Residual |  731.653555        68  10.7596111   R-squared       =    0.7006
        -------------+----------------------------------   Adj R-squared   =    0.6785
               Total |  2443.45946        73  33.4720474   Root MSE        =    3.2802
        
        ---------------------------------------------------------------------------------------
                          mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        ----------------------+----------------------------------------------------------------
                      foreign |
                     Foreign  |   1.592256   23.34741     0.07   0.946    -44.99678    48.18129
                         tons |  -26.34354   9.536229    -2.76   0.007    -45.37279   -7.314293
                              |
               foreign#c.tons |
                     Foreign  |  -.0928684   36.88567    -0.00   0.998    -73.69707    73.51133
                              |
                c.tons#c.tons |   4.451742   2.921031     1.52   0.132    -1.377084    10.28057
                              |
        foreign#c.tons#c.tons |
                     Foreign  |  -2.252604   14.27307    -0.16   0.875    -30.73407    26.22886
                              |
                        _cons |    50.7455   7.618435     6.66   0.000     35.54315    65.94786
        ---------------------------------------------------------------------------------------
        
        . margins, at(tons=(.8(.05)2.4)) over(r.for)
        
        <snip>
        
        . marginsplot, yline(0)
        
        Variables that uniquely identify margins: tons
        
        .
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          If I applied the code correctly the correct code should be (given 33 countries in dataset):
          Code:
          xtset essround
          xtreg c.intolerance i.børn i.indkomst c.eduyrs c.agea i.cntry2, robust fe
          margins, at(cntry2=(1(1)33)) over(r.børn)
          marginsplot, yline(0)
          However, this gives me this graph
          Click image for larger version

Name:	a.PNG
Views:	1
Size:	58.6 KB
ID:	1649112


          Best regards

          Comment


          • #6
            Christian:
            let's change the last line of my previous code as follows:
            Code:
            marginsplot, yline(0) xlabel(, angle(90)) xlabel(#33)
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Carlo:
              It did display all countries but estimates are still wrong
              Click image for larger version

Name:	4.PNG
Views:	1
Size:	66.3 KB
ID:	1649128

              Best regards

              Comment


              • #8
                Christian:
                what if:
                Code:
                xtset essround
                xtreg c.intolerance i.børn i.indkomst c.eduyrs c.agea i.cntry2, robust fe
                margins, at(cntry2=(1(1)33))
                marginsplot, yline(0) xlabel(,angle(90)) xlabel(#33)
                Kind regards,
                Carlo
                (StataNow 18.5)

                Comment


                • #9
                  This looks more accurate but I the estimates still seem wrong:
                  Click image for larger version

Name:	5.PNG
Views:	1
Size:	83.8 KB
ID:	1649138





                  For example estimating the effect in Austria (country 1 in dataset) using:
                  Code:
                  xtset essround
                  xtreg c.intolerance i.børn c.agea i.indkomst c.eduyrs if cntry2 ==1, robust fe
                  I get the estimate 0.0168 (insignificant) which doesn't fit with the value >5 on the graph.

                  Kind regards
                  Last edited by Christian BH; 08 Feb 2022, 13:33.

                  Comment


                  • #10
                    Christian:
                    please note that the graph reports the linear prediction for each country (that differ from the country-specific coefficients you get).
                    Just try:
                    Code:
                    predict fitted, xb
                    after -xtreg- and compare what you get vs the values reported on the graph.
                    Kind regards,
                    Carlo
                    (StataNow 18.5)

                    Comment

                    Working...
                    X