Announcement

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

  • X-Axis show half plot

    Hello Statalist, I use the below code which makes the below graph. I don't know why the year 2006 does not display the chart. any solution, please???

    Code:
    preserve
    keep if inlist(year, 2002 , 2003, 2005, 2006)
    
    gen event = year - 2004 + 100
    tab event
    xtreg st1 ib100.event i.year i.treat $cl, fe i(stkcd) cluster(stkcd)
    eststo st1p
    coefplot st1p, keep(*.event) vert rename(*.event="") xtitle("Years") ytitle("ST1") xlabel(1 "2002" 2 "2003" 3 "2005" 4 "2006") xscale(range(0.5 4.5)) name(st1_upper, replace)

    Below is the data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(st1 event) float year double treat
                       .  98 2002 0
                       .  99 2003 0
                       . 101 2005 0
                       0 102 2006 0
      .09604616696929251  98 2002 0
      .28962622471456256  99 2003 0
      .06710824471689544 101 2005 0
      .08620013879570665 102 2006 0
       .6662144718507561  98 2002 0
       .6029833501337559  99 2003 0
       .4898758380528328 101 2005 0
       .2651543595305284 102 2006 0
       .5568158447725238  98 2002 0
       .5820257081493239  99 2003 0
      .39235363450130195 101 2005 0
        .441954794730697 102 2006 0
       .3098061216205315  98 2002 0
      .31966307412355016  99 2003 0
      .30206380882394623 101 2005 0
       .4081601935245437 102 2006 0
       .5270173664040717  98 2002 0
       .5838580271282523  99 2003 0
       .6602583189751736 101 2005 0
       .6090947192607512 102 2006 0
       .3613609940808387  98 2002 0
       .3345362221399254  99 2003 0
       .2502982744180982 101 2005 0
      .20914447364739341 102 2006 0
        .320553016823736  98 2002 0
       .3513748248164273  99 2003 0
       .4028876443683232 101 2005 0
      .04001263924960175 102 2006 0
      .34580344868702845  98 2002 1
      .36041677565924674  99 2003 1
       .4046321058365264 101 2005 1
       .3866869174226278 102 2006 1
       .5589146932798127  98 2002 0
       .5664086417948185  99 2003 0
      .30870132438471803 101 2005 0
       .2721147184531201 102 2006 0
       .3810061466231089  98 2002 1
      .27196101073408385  99 2003 1
      .21549063140258673  98 2002 0
      .31684958830123644  99 2003 0
      .15386760175179565 101 2005 0
      .29207055014036587 102 2006 0
      .03454964155295443  98 2002 0
    .0037084165530211354  99 2003 0
       .0049528033575212 101 2005 0
     .002341256058221906 102 2006 0
      .18514068258937158  98 2002 1
      .20845330098283474  99 2003 1
       .2152675321755276 101 2005 1
         .20596810358499 102 2006 1
       .6330952325073145  98 2002 1
       .6975774214228182  99 2003 1
       .5103128519828921 101 2005 1
       .4280376449167185 102 2006 1
       .6098343936781896  98 2002 0
       .6359622517903386  99 2003 0
       .4213816921473605 101 2005 0
        .521120432391642 102 2006 0
       .6701561894010253  98 2002 1
       .6706641805010028  99 2003 1
       .6259713721975206 101 2005 1
      .44221327825139806 102 2006 1
     .000724298577907034  98 2002 0
    .0010635444618339396  99 2003 0
                       0 101 2005 0
                       0 102 2006 0
       .5460841052795266  98 2002 0
       .3264975633382865  99 2003 0
       .4600696907500765 101 2005 0
       .6314494112229786 102 2006 0
       .5433364179462896  98 2002 0
       .6247981813914562  99 2003 0
        .325480416876663 101 2005 0
       .2268838619325507 102 2006 0
      .16258155907103944  98 2002 1
      .26201567935248044  99 2003 1
      .32809808873984503 101 2005 1
      .22732999369263898 102 2006 1
       .4898328134968033  98 2002 1
       .4207752846077022  99 2003 1
       .3839122176760559 101 2005 1
      .34959561429621605 102 2006 1
      .08065393240547168  98 2002 1
     .001995294934919864  99 2003 1
        .248751191068432 101 2005 1
       .6939867296277917 102 2006 1
      .06381824984791717  98 2002 1
      .03444830617789382  99 2003 1
      .04457600352451833 101 2005 1
      .10103184057715188 102 2006 1
        .239804659084622  98 2002 0
      .28604304438985106  99 2003 0
     .014733469046230997 101 2005 0
       .1346057898371778 102 2006 0
      .40398044237865693  98 2002 0
       .4143122286652363  99 2003 0
    end
    format %ty year

    Click image for larger version

Name:	st1_upper.jpg
Views:	1
Size:	91.7 KB
ID:	1722924

    Last edited by Obaid Ur Rehman; 04 Aug 2023, 22:52.

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). Show us your xtreg results.

    Comment


    • #3
      Code:
      xtreg st1 ib100.event i.year i.treat $cl, fe i(stkcd) cluster(stkcd)
      note: 100b.event identifies no observations in the sample.
      note: 102.event omitted because of collinearity.
      note: 2003.year omitted because of collinearity.
      note: 2005.year omitted because of collinearity.
      note: 2006.year omitted because of collinearity.
      note: 1.treat omitted because of collinearity.
      
      Fixed-effects (within) regression               Number of obs     =      5,490
      Group variable: stkcd                           Number of groups  =      1,528
      
      R-squared:                                      Obs per group:
           Within  = 0.0961                                         min =          1
           Between = 0.0026                                         avg =        3.6
           Overall = 0.0202                                         max =          4
      
                                                      F(12,1527)        =      22.88
      corr(u_i, Xb) = -0.0860                         Prob > F          =     0.0000
      
                                    (Std. err. adjusted for 1,528 clusters in stkcd)
      ------------------------------------------------------------------------------
                   |               Robust
               st1 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
             event |
               98  |   .0822488   .0097897     8.40   0.000      .063046    .1014515
               99  |   .0845076   .0087797     9.63   0.000      .067286    .1017291
              100  |          0  (empty)
              101  |    .019103   .0038677     4.94   0.000     .0115163    .0266896
              102  |          0  (omitted)
                   |
              year |
             2003  |          0  (omitted)
             2005  |          0  (omitted)
             2006  |          0  (omitted)
                   |
           1.treat |          0  (omitted)
              size |   .0253561   .0104489     2.43   0.015     .0048603    .0458518
               lev |   .0255446   .0332853     0.77   0.443     -.039745    .0908343
              prof |  -.3001358    .041417    -7.25   0.000    -.3813761   -.2188955
                 q |   .0087745   .0065781     1.33   0.182    -.0041286    .0216776
              tang |   .1099002   .0218948     5.02   0.000     .0669531    .1528474
              dlev |   .0134716     .02131     0.63   0.527    -.0283285    .0552716
            accint |  -.2210474   .0225716    -9.79   0.000     -.265322   -.1767728
              inef |   .0143573   .0609268     0.24   0.814    -.1051518    .1338664
              fage |    .000579   .0017897     0.32   0.746    -.0029316    .0040896
             _cons |   -.273388    .218039    -1.25   0.210    -.7010756    .1542995
      -------------+----------------------------------------------------------------
           sigma_u |  .18979683
           sigma_e |   .1234366
               rho |  .70275531   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      
      . eststo st1p

      Comment


      • #4
        There is nothing to show here as the coefficient is omitted.

        ------------------------------------------------------------------------------
        | Robust
        st1 | Coefficient std. err. t P>|t| [95% conf. interval]
        -------------+----------------------------------------------------------------
        event |
        98 | .0822488 .0097897 8.40 0.000 .063046 .1014515
        99 | .0845076 .0087797 9.63 0.000 .067286 .1017291
        100 | 0 (empty)
        101 | .019103 .0038677 4.94 0.000 .0115163 .0266896
        102 | 0 (omitted)
        If you want to indicate that the coefficient is omitted and show a marker at 0, use the option -omitted-.

        Code:
        coefplot st1p, keep(*.event) omitted vert rename(*.event="") xtitle("Years") ytitle("ST1") xlabel(1 "2002" 2 "2003" 3 "2005" 4 "2006") xscale(range(0.5 4.5)) name(st1_upper, replace)
        This however may be confusing in the case that the reader interprets it as the base level.

        Comment


        • #5
          i don't know why year 2006 observation dropped. below are my data characteristics:

          Code:
          tab treat
          
                treat |      Freq.     Percent        Cum.
          ------------+-----------------------------------
                    0 |      3,007       54.50       54.50
                    1 |      2,510       45.50      100.00
          ------------+-----------------------------------
                Total |      5,517      100.00
          
          . 
          . gen event = year - 2004 + 100
          
          . tab event
          
                event |      Freq.     Percent        Cum.
          ------------+-----------------------------------
                   98 |      1,275       23.11       23.11
                   99 |      1,332       24.14       47.25
                  101 |      1,416       25.67       72.92
                  102 |      1,494       27.08      100.00
          ------------+-----------------------------------
                Total |      5,517      100.00

          Comment


          • #6
            .
            Last edited by Obaid Ur Rehman; 05 Aug 2023, 11:33.

            Comment


            • #7
              As you have 4 event years


              . tab event

              event | Freq. Percent Cum.
              ------------+-----------------------------------
              98 | 1,275 23.11 23.11
              99 | 1,332 24.14 47.25
              101 | 1,416 25.67 72.92
              102 | 1,494 27.08 100.00
              ------------+-----------------------------------
              Total | 5,517 100.00
              including

              xtreg st1 ib100.event i.year
              is equivalent to specifying a non-existent base. So Stata has to break the collinearity and takes 2006 (or event= 102) as the base. For an explanation, google the dummy variable trap.

              Comment


              • #8
                Thanks, Andrew, i get the idea from your suggestion. below is the solution:

                Code:
                keep if inlist(year, 2002 , 2003, 2005, 2006, 2007)
                
                gen event = year - 2004 + 100
                tab event
                
                xtreg st1 ib100.event i.year i.treat $cl, fe i(stkcd) cluster(stkcd)
                eststo st1p
                coefplot st1p, keep(*.event) vert rename(*.event="") xtitle("Years") ytitle("ST1") xlabel(1 "2002" 2 "2003" 3 "2005" 4 "2006") xscale(range(0.5 4.5)) name(st1_upper, replace)
                Click image for larger version

Name:	Screenshot 2023-08-06 at 1.45.44 PM.png
Views:	1
Size:	667.3 KB
ID:	1723013
                Last edited by Obaid Ur Rehman; 05 Aug 2023, 23:53.

                Comment

                Working...
                X