Announcement

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

  • Plotting results using Coefplot

    Hi Statalist,
    I am trying to visually present my regression results. I would like to plot main effects as bar charts with error bars 95% confidence interval. This is the code I’ve run, it combines the results of three models in one graph:

    Code:
    xtreg M1  dbirthstat2 dsondum21 spercent2 totalchild i.educ i.releduc i.qwealth i.employment durban1 dlivingstructure1 age firstbirthage agegap agemarriage gdp1 i.round, re theta
    est store Financial
    xtreg D1  dbirthstat2 dsondum21 spercent2 totalchild i.educ i.releduc i.qwealth i.employment durban1 dlivingstructure1 age firstbirthage agegap agemarriage gdp1 i.round, re theta
    est store Daily
    xtreg C1  dbirthstat2 dsondum21 spercent2 totalchild i.educ i.releduc i.qwealth i.employment durban1 dlivingstructure1 age firstbirthage agegap agemarriage gdp1 i.round, re theta
    est store Children
    coefplot Financial Daily Children, vertical recast(bar) barwidth(0.25) fcolor(*.5) ciopts(recast(rcap)) citop  ytitle(Linear prediction) keep (dbirthstat2 dsondum21)
    This code works fine (included as attachment). However, when I run the code below to plot the coefficents for educ and releduc I get the following error message
    Code:
    coefplot Financial Daily Children, vertical recast(bar) barwidth(0.25) fcolor(*.5) ciopts(recast(rcap)) citop  ytitle(Linear prediction) keep (educ releduc)
    (Financial: no coefficients found, all dropped, or none kept)
    (Daily: no coefficients found, all dropped, or none kept)
    (Children: no coefficients found, all dropped, or none kept)
    (nothing to plot)
    I have not dropped my model estimates so I am not sure why there is nothing to plot
    Attached Files

  • #2
    Because neither educ nor releduc are in your estimation commands. You have i.year and i.releduc

    If you use -xtreg, coefleg- it will show the names of the coefficients. You can reference them in -coefplot with keep(*year *releduc). For example


    Code:
    . webuse grunfeld,clear
    
    . qui xtreg invest mvalue kstock i.year, fe
    
    . est store A
    
    . xtreg , coefleg
    
    Fixed-effects (within) regression               Number of obs     =        200
    Group variable: company                         Number of groups  =         10
    
    R-sq:                                           Obs per group:
         within  = 0.7985                                         min =         20
         between = 0.8143                                         avg =       20.0
         overall = 0.8068                                         max =         20
    
                                                    F(21,169)         =      31.90
    corr(u_i, Xb)  = -0.3250                        Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          invest |      Coef.  Legend
    -------------+----------------------------------------------------------------
          mvalue |   .1177158  _b[mvalue]
          kstock |   .3579163  _b[kstock]
                 |
            year |
           1936  |  -19.19741  _b[1936.year]
           1937  |  -40.69001  _b[1937.year]
           1938  |   -39.2264  _b[1938.year]
           1939  |  -69.47029  _b[1939.year]
           1940  |  -44.23507  _b[1940.year]
           1941  |  -18.80446  _b[1941.year]
           1942  |  -21.13979  _b[1942.year]
           1943  |  -42.97762  _b[1943.year]
           1944  |  -43.09876  _b[1944.year]
           1945  |  -55.68303  _b[1945.year]
           1946  |  -31.16928  _b[1946.year]
           1947  |  -39.39223  _b[1947.year]
           1948  |  -43.71651  _b[1948.year]
           1949  |   -73.4951  _b[1949.year]
           1950  |  -75.89611  _b[1950.year]
           1951  |   -62.4809  _b[1951.year]
           1952  |  -64.63233  _b[1952.year]
           1953  |  -67.71796  _b[1953.year]
           1954  |  -93.52622  _b[1954.year]
                 |
           _cons |  -32.83631  _b[_cons]
    -------------+----------------------------------------------------------------
         sigma_u |  91.798268
         sigma_e |  51.724523
             rho |  .75902159   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(9, 169) = 52.36                     Prob > F = 0.0000
    
    . coefplot A, vertical recast(bar) keep(*year) /// 
    >         barwidth(0.25) fcolor(*.5) ciopts(recast(rcap)) citop

    Comment


    • #3
      Thank you Scott, the clears it up for me.

      Comment

      Working...
      X