Announcement

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

  • Plot one coefficient of a regression for different time intervals using coefplot

    Hi Everyone,

    I am looking to plot a coefficient of a variable for a regression using panel data. Here is an example of relevant variables:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(log_quantity log_price) int monthly
     7.516082 2.3769064 659
     8.087429 2.3010998 660
    8.2177725  2.285712 661
     8.421479 2.2828755 662
     8.486928 2.2437243 663
      8.64822 2.1839561 664
     8.669524 2.1738276 665
     8.874057 1.9249498 666
     9.017177  1.921546 667
     9.024445  1.920314 668
     9.204823   1.91248 669
     9.127684 1.9294425 670
      9.32783 1.8838995 671
     9.329835 1.8669082 672
     9.331509  1.907229 673
    end
    format %tm monthly

    I am running one regression, but want to plot the coefficient of quantity as measured by 6 month intervals. For example, one point on the graph would be the coefficient of log_quantity for months 659 to 664, then 665 to 669, etc. For the graph, I would prefer to have the y-axis measure the coefficient value, and the x-axis measure time. I also do not mind if confidence intervals are included.

    Here is an example of my coefplot code:

    coefplot (interval1, label(1) lcolor(maroon) lwidth(thick)), keep(log_quantity) base vertical noci xlabel(1 "2014" 2 "2015" 3 "2016" 4 "2016" 5 "2018") yline(0) name(PriceResponse) xtitle(Time) ytitle(Coefficient of Log Qt)


    How can I achieve this so each coefficient measurement represents one particular interval?

    Thank you in advance!

  • #2
    This thread might guide you to that which you seek. You'll basically make it into a matrix

    Comment


    • #3
      Materials (papers, presentations) on the user community contributed Stata command coefplot is available on the authors website here.
      Plotting results from matrices is discussed on the page Getting started - how to use coefplot.
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Thank you both so much!! I have been looking through the document that discusses plotting results from the matrix.
        I have tried to create the matrix to then plot, but have been stuck. Her is what I tried

        xtabond2 log_price L.log_quantity L.log_price log_usableweight if monthly>=662 & monthly==667, gmm(log_price, lag(3 3) eq(diff)) iv(log_quantity, eq(diff)) twostep robust
        local coef1=_b[L.log_quantity]

        I did this 5 times (did not loop. Eventually I will for other graphs).

        then I tried

        matrix Z = (coef1,coef2,coef3,coef4,coef5)

        but it won't recognize any of the entries. I have tried a different way to extract coefficients too.


        mat Beta1=e(b)
        local coef1=el(Beta1,1,1)

        This didn't work either.

        How can I fix this so I can graph the matrix?


        Comment


        • #5
          So let me ensure I understand you well: you want to plot the average 6 month effect size of one coefficient? So let's say you've got 2 years, you'd have 4 plotted points, right? Is that pretty much what we're discussing here?

          Comment


          • #6
            Essentially, yes. I am trying to plot how the coefficient varies over time.
            Eventually I will expand upon this, or can expand the matrix to include other variables, but that is the base idea I need to hammer out for a proof of concept.

            Am I missing a super easy method of doing this?

            Comment


            • #7
              Allow me to use an empirical example from the literature. Note that you cannot replicate this because scul is not on SSC yet.
              Code:
              u "http://econ.korea.ac.kr/~chirokhan/panelbook/data/basque-clean.dta", clear
              
              replace regionname = "Asturias" if regionname=="Principado De Asturias" 
              
              loc int_time = 1975
              
              //sysuse basque, clear
              
              g treated = cond(regionno==17 & year >= `int_time',1,0)
              
              tempvar _XnormVar _xXnormVar
              
              labvars year gdpcap "Year" "ln(GDP per 100,000)"
              
              replace regionname = trim(regexr(regionname,"\(.+\) *",""))
              
              egen id = group(regionname), label(regionname) // makes a unique ID
              
              order id, b(year)
              
              *keep if year >= 1960
              drop if inlist(id,18) //12
              
              keep gdp id year
              xtset id year, y
              
              cd "E:\Test"
              
              scul gdpcap, ahead(3) trdate(`int_time') ///
              trunit(5) lamb(lopt) ///
              scheme(white_tableau) ///
              obscol(black) cfcol(red) legpos(11)
              
              u "scul_Basque Country", clear
              
              cls
              I estimate the causal impact of terrorism on GDP per Capita, as in Abadie's paper. We get the following
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input float(diff_ relative)
                .03842559 -20
              -.004970317 -19
               -.04794306 -18
               -.09953115 -17
               -.14885448 -16
               -.14062054 -15
               -.12302083 -14
               -.04280565 -13
                .02035868 -12
                .07518516 -11
                .12601018 -10
                .09928696  -9
                .06439175  -8
                .07657699  -7
                .07846317  -6
               .021340854  -5
              -.015658611  -4
               -.03050518  -3
               -.05360032  -2
                .10747079  -1
                 .2553361   0
                .07981432   1
               -.09252395   2
                -.3515895   3
                -.5095963   4
                 -.640677   5
                -.7888506   6
                -.8381464   7
                -.8908237   8
                -.8211216   9
                -.7477256  10
                -.7814611  11
                -.8055214  12
                -.8414215  13
                -.8698893  14
                 -.863242  15
                -.8696404  16
                -.8678145  17
                -.8696176  18
                -.9027553  19
                -.7602502  20
                -.7425429  21
                -.6728792  22
              end
              
              
              cls
              
              br
              keep if inrange(rel,-10,4)
              
              egen avvar = seq(), from(1) to(3) b(5)
              
              collapse diff, by(avvar)
              
              tw (connected diff av)
              What I've done here, is I've created an arbitrary 5 year average of effect sizes. we have 10 periods before the intervention, and 5 in the post intervention.

              Of course, I've broken them up into 3's since I make a new number with egen every 5 years, which means we'll have 2 pre-points, and 1 post point. And, that's what we do see, 2 pre-points and one post point as soon as the intervention began. Perhaps, you could so something similar to your case. Is this roughly the idea of what you're looking for?

              Comment

              Working...
              X