Announcement

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

  • Replicating fitted values graph



    Hi all,

    I am hoping to replicate a graph from this paper in Political Analysis. The graph, attached below, compares fitted values from pooled TSCS and FE TSCS analyses, along with the slopes of the individual panels, along axes for the X and Y variables of interest. I feel like this should be relatively simple to obtain, but I can't figure out where to begin. Does anyone have some guidance on this?

    Thanks!



    Click image for larger version

Name:	Screenshot 2019-01-09 at 18.45.54.png
Views:	1
Size:	77.5 KB
ID:	1477985

  • #2
    Here is one example:

    Code:
    webuse grunfeld, clear
    levelsof company, local(levels)
    qui {
        foreach l of local levels {
            reg invest kstock  if comp == `l'
            predict fitted`l' if comp == `l'
        }
        reg invest kstock
        predict fitted_pooled
        xtreg invest kstock, fe
        predict fitted_fe
    }
    line fitted1-fitted10 kstock, sort lp(dash..) lc(gs5..) lw(thin..) /// 
      || line fitted_pool kstock , sort lc(black) lw(thick) /// 
      || line fitted_fe kstock , sort lc(blue) lp(dash) lw(thick) /// 
      ||, legend(order (1 "Individal" 11 "Pooled" 12 "FE"))

    Comment


    • #3
      Thank you, Scott! Works perfectly. Appreciate the time.

      Comment


      • #4
        Apologies - an additional question.

        The graph breaks down when additional variables are added. Unless I am mistaken, the authors in the paper produce this graph from a regression with multiple variables. Do they do so by simply adding a line of best fit, or is there something else going on? Many thanks again.

        Comment


        • #5
          I would guess they are replacing the other variables with their means. Here are two ways:

          Code:
          webuse grunfeld, clear
          gen m2 = mvalue
          levelsof company, local(levels)
          qui {
              foreach l of local levels {
                  reg invest kstock mvalue if comp == `l'
                  sum mvalue if com == `l'
                  replace mvalue = r(mean)
                  predict fitted`l' if comp == `l'
                  replace mvalue =m2
              }
              reg invest kstock mvalue
              sum mvalue
              replace mvalue = r(mean)
              predict fitted_pooled
              replace mvalue =m2
              
              xtreg invest kstock mvalue, fe
              sum mvalue
              replace mvalue = r(mean)
              predict fitted_fe
              replace mvalue =m2
          }
          line fitted1-fitted10 kstock, sort lp(dash..) lc(gs5..) lw(thin..) /// 
            || line fitted_pool kstock , sort lc(black) lw(thick) /// 
            || line fitted_fe kstock , sort lc(blue) lp(dash) lw(thick) /// 
            ||, legend(order (1 "Individual" 11 "Pooled" 12 "FE")) name(gr1,replace)
          Click image for larger version

Name:	gr1.png
Views:	1
Size:	28.8 KB
ID:	1478112


          Code:
          webuse grunfeld, clear
          levelsof company, local(levels)
          qui {
              foreach l of local levels {
                 reg invest kstock mvalue  if comp == `l'
                 margins if com == `l', at(kstock = (100(100)2000)) atmeans saving(m`l',replace)
              }
          
              reg invest kstock mvalue
              margins, at(kstock = (100(100)2000)) atmeans saving(m11,replace)
              xtreg invest kstock mvalue, fe
              margins, at(kstock = (100(100)2000)) atmeans saving(m12,replace)
          
              forv i = 1/12  {    
                  use m`i',clear
                  rename (_margin _at1) ( margin`i' kstock)
                  if `i' == 1 {
                      keep margin kstock
                      order kstock margin
                  }
                  else {
                      keep margin
                  }
                  save,replace
                  
          }
              use m1,clear
              forv i = 2/12  {    
                  merge 1:1 _n using  m`i', nogenerate
              }
          }
          line margin1-margin10 kstock, sort lp(dash..) lc(gs5..) lw(thin..) /// 
            || line margin11 kstock , sort lc(black) lw(thick) /// 
            || line margin12 kstock , sort lc(blue) lp(dash) lw(thick) /// 
            ||, legend(order (1 "Individual" 11 "Pooled" 12 "FE"))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	43.2 KB
ID:	1478113

          Comment


          • #6
            Scott,

            Thanks again! For what it's worth, that is identical to running the same models and fitting a line of best fit for each fitted model. That is certainly less elegant than your solution however.

            Some quirk that occurs in my own data though: the graphs as above display a positive relationship, but the coefficient in the pooled/FE models are negative. I can't seem to figure out why. Any ideas about why this may be? I appreciate this is difficult without seeing the data, but it is just on the off chance someone had a potential avenue for me to look at.

            Thanks for all your help!

            Comment

            Working...
            X