Announcement

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

  • Plotting a graph of the regression coefficients

    Dear all,

    I have a very difficult problem that I can't seem to produce using Stata. I am using the package coefplot, but I can't get the correct result.

    Suppose I have the following code:

    Code:
    reg weight if day == 1
    
    estimates store d1
    
    reg weight if day == 2
    
    estimates store d2
    
    ...
    Now what I would like to do is plot the coefficients on the y-axis and days on the x-axis preferably including the 95% confidence interval lines. So I have three lines in 1 graph, is this possible to do in Stata 13.1 or should I use a different package to do this?

    PS: in this case there is only one coefficient, but I if there are multiple coefficients is there a way to select the coefficient that I would like to plot?

    There is btw one method that I know it will work and that's by making a new data file as follows:

    coefficient - day - ci_top - ci_bottom
    1.1 - 1 - 1.5 - 0.9
    ...

    and then plot this, but this seems a bit weird I think.

    Thanks for your help!
    Last edited by bsc.j.j.w; 02 Jul 2014, 16:21.

  • #2
    Is this close to what you want?

    Code:
    sysuse auto, clear
    regress price if foreign==0
    est sto domestic
    regress price if foreign==1
    est sto foreign
    coefplot domestic foreign, vert
    You wouldn't actually get days on the X axis, but you would have the names of the estimates. Or, maybe

    Code:
    regress price ibn.foreign, nocons
    coefplot, vert
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Dear Richard,

      thank you for your reply. This is indeed similar to what I want (which is also similar to the examples in this document: ftp://repec.sowi.unibe.ch/files/wp1/...3-coefplot.pdf), however I would like the CI lines to be connected and the dots of my observations also connected. In the document on page 30, the graph at the bottom corresponds exactly to what I want, except on the y-axis I have the "different kinds of regressions" (i.e. day 1, day 2 etc.). Oh and also of course the

      Code:
      proportion varlist
      should be reg actually in my case. Upon closer look, this is a bit different than the figure on page 30, since I would like to connect over the regressions, while the example only connects the dots in one estimation. It is also quite possible that this feat. cannot be achieved with
      Code:
      coefplot
      , but maybe with
      Code:
      eclplot
      .

      Upon further investigation, I played a bit with the eclplot package:

      Code:
      use http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta, clear
      sencode label if parm~="_cons", gen(parmid)
      list parm label est min95 max95 parmid 
      eclplot estimate min95 max95 parmid, horiz
      What this does is actually generating a new dataset with the estimates, which is quite impressive in my opinion and makes it all easier. However I left out a second problem and that is: my estimates are generated using a bootstrap method described here: http://www.stata-journal.com/sjpdf.h...iclenum=st0073.

      The question assuming that I will have to use eclplot is whether it is possible for me now to use the bootstrapped estimates?
      Last edited by bsc.j.j.w; 03 Jul 2014, 01:18. Reason: Found new evidence that might help others that have the same question.

      Comment


      • #4
        Sorry, this goes beyond my expertise with graphics. If anybody else is interested -coefplot- is available from SSC. If you want to try out -coefplot- Ben Jann has an entire paper on it at

        ftp://repec.sowi.unibe.ch/files/wp1/...3-coefplot.pdf
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Here is the code I used (I changed the variable names) for creating a coefficient plot with CI, you need to install parmest:

          **

          qui: reg y x1 x1 x2, vce(robust)
          parmest, label list(parm label estimate min* max* p) saving(results, replace)
          use results, clear
          drop in 6
          encode parm, generate(parm2)
          drop parm
          rename parm2 parm
          label variable estimate "regression coefficient"
          label variable min95 "lower 95% CI "
          label variable max95 " upper 95% CI"
          twoway (scatter estimate parm, mcolor(black) msymbol(square) msize(small)) (rcap min95 max95 parm, lcolor(black)), xlabel(, valuelabels angle(0) labsize(vsmall)) xtitle("")

          **

          That should work.
          Last edited by Nick Bornschein; 03 Jul 2014, 09:04.

          Comment


          • #6
            Dear all,

            thank you Nick, the code is very clear. Eventually I solved it using the same method. For those who are interested, it basically boils down to:

            - First do for every regression a parmest, saving(...).
            - Second for all the estimation files you should append them all.
            - Third make a nice scatter plot.

            (Code could probably be optimized)

            For those who are interested in the code, please PM me. It just boils down to "automatically" input the parameters in a new dataset, this was actually the thing I tried to avoid, since I thought it would be possible to "realtime" derive the coefficients stored in the memory.

            Thanks for all of your suggestions.

            Comment


            • #7

              hey bsc.j.j.w, please post you code, I have to do the same by year, 15 years.

              And plot only one coefficient in a multiple regression against 15 years
              Kind regards,
              Sergey Alexeev | ​The University of Sydney
              https://alexeev.pw/

              Comment


              • #8
                Dear all,

                I also have a very similar inquiry.

                I want to plot the coefficients of regression coefficient in a graph for each of the 5 estimated lags along with 1 standard error band in quarterly time series dataset .The dataset looks as follows:


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input int year byte quart float logIP byte Geopolshock
                1978 3  2.428907 0
                1978 4 2.6631305 0
                1979 1  2.736929 0
                1979 2 2.6303246 0
                1979 3   2.60231 0
                1979 4   2.74495 0
                1980 1  2.848178 1
                1980 2  2.733792 1
                1980 3 2.6796124 1
                1980 4  2.867407 1
                end

                In the above discussed coefplot command the "at" option does not work with my regression. The regressions I run along with my variable of interest Geopolshock is as follows:


                Code:
                reg logIP l(1/5).Geopolshock quietly eststo bivariate, at(quart=(1(1)5))
                reg logIP l(1/5).Geopolshock l.l(1/5).logIP
                quietly eststo multivariatewithlags, at(quart=(1(1)5))
                coefplot bivariate multivariatewithlags, at ytitle(logIP) xtitle(Quarters) /// recast(line) lwidth(*2) ciopts(recast(rline) lpattern(dash))
                Now, I want to plot for every quarter coefficient with one standard error band and see impact of Geopolshock on LogIP, how can I do this? Thank you very much and look forward to your help.

                Cheers,
                Sultan
                P.S: example of required output is given below (source: Romer and Romer, 2010)
                Click image for larger version

Name:	image_7490.png
Views:	2
Size:	23.3 KB
ID:	1384923

                Last edited by Sultan Mehmood; 22 Apr 2017, 04:32.

                Comment

                Working...
                X