Announcement

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

  • graph x-axis with year and month?

    Dear All, I use the (ssc install) -synth- command to tun the following regression
    Code:
    xtset id date
    sort  id date
    synth ageneral ageneral(`=tm(2010m4)') ageneral(`=tm(2009m4)') ageneral(`=tm(2008m4)'), trunit(8) trperiod(`=tm(2010m5)') fig
    and obtain the graph
    Click image for larger version

Name:	synth_garbage.png
Views:	1
Size:	126.8 KB
ID:	1524456


    My question is: how can I obtain readable year and month in the horizontal x axis instead of number 500, 550, and so on. Thanks.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    I would try an option like

    Code:
    xla(480(60)720, "%tm")
    on the grounds that 480 is 2000m1 and 720 is 2020m1 and 60 months is 5 years.

    Comment


    • #3
      Dear Nick, Thanks for the suggestion. However, I encountered a problem as below. The data is
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(_Co_Number _W_Weight) double(_Y_treated _Y_synthetic _time)
       1 .002  .7486965656280518  .7210599974393844 544
       2 .296   .739027202129364   .724936309605837 545
       3 .002  .6910927891731262  .7080179764032364 546
       4 .002  .7093546986579895  .7016765946447848 547
       5 .001  .6787251830101013  .7391154565811155 548
       6 .002  .6441994905471802   .667621375322342 549
       7 .002  .6310403347015381   .676353806644678 550
       9 .002  .6618160009384155  .6335205880105494 551
      10 .001  .6882448196411133  .6940624381899834 552
      11 .022  .6502036452293396  .6943669224381447 553
      12 .001  .5117933750152588  .6367492630779743 554
      13 .002  .5611556172370911  .6455466538369655 555
      14 .002  .6245927214622498   .660534980416298 556
      15 .001  .6486433148384094  .6750415651202203 557
      16 .659  .6294874548912048  .6268251437842847 558
      17 .001  .6069641709327698  .6356893200874328 559
      18 .002  .5863736271858215  .6269650571346284 560
       .    .  .5721890926361084  .6320942456722259 561
       .    .  .5853404402732849  .6552347394227983 562
       .    .  .5867512822151184  .6111418328285217 563
       .    .  .6318464279174805  .6183595074713231 564
       .    .  .6898829936981201  .7464224513173101 565
       .    .  .6046586036682129  .6259028042852878 566
       .    .  .6088652014732361  .6337817425131796 567
       .    .  .6143525242805481  .6343774201273918 568
       .    .   .627411961555481   .682987024307251 569
       .    .  .5956853628158569   .626796017229557 570
       .    .  .6162302494049072  .6219144042134286 571
       .    .   .548919677734375  .5849772656559944 572
       .    .  .5702694058418274   .597943552017212 573
       .    .  .5312939882278442  .5689887872636318 574
       .    .  .5458453893661499  .5678441866338254 575
       .    .  .6222614049911499  .5922572453916074 576
       .    .  .6347241401672363  .6391547411084176 577
       .    .  .5497625470161438  .5405646896660328 578
       .    .  .5576375722885132  .5577426072955132 579
       .    .  .5762714743614197  .5676418633460998 580
       .    .  .5788170099258423  .5881268804371356 581
       .    .  .5557138323783875  .5819388562142849 582
       .    .  .5067449808120728  .5326719032227993 583
       .    .  .5527967214584351  .5500263779759408 584
       .    .  .5112394690513611   .519830498367548 585
       .    .  .4944966435432434 .47253187692165377 586
       .    .  .5351616144180298  .5022300747632981 587
       .    .  .6038393378257751  .5909580431580542 588
       .    .  .5445702075958252  .5358137893080711 589
       .    .  .5102695822715759  .5098407264649869 590
       .    .  .5232247710227966  .5233317140042781 591
       .    .  .5077580213546753  .5217399259209633 592
       .    .  .5631242990493774  .5882199471592905 593
       .    .  .4979035258293152  .5371619039773942 594
       .    . .47456610202789307   .548754320770502 595
       .    .  .4531645178794861  .4894840043485164 596
       .    .  .4799719452857971  .5097716262340545 597
       .    .  .4900871217250824 .48590489745140075 598
       .    . .42871353030204773  .4816024653315544 599
       .    .  .5540602207183838 .49409413212537767 600
       .    .  .5847893953323364  .5969827520251275 601
       .    .  .4825137257575989   .498152988344431 602
       .    .  .4818187355995178 .48191374143958093 603
       .    .  .5010020732879639  .4957556169927121 604
       .    .  .5272852778434753  .5267929123044015 605
       .    . .43827328085899353  .4989800226092339 606
       .    .  .3930318355560303  .4864072996675968 607
       .    .  .3923063576221466  .5059635001420976 608
       .    . .37860190868377686  .4524436955153942 609
       .    .  .3463653326034546 .46548317924141885 610
       .    .  .2723841369152069 .45516663289070136 611
       .    .  .3171271085739136  .5111449680030347 612
       .    .  .3008332848548889 .49755009964108465 613
       .    . .26196423172950745  .4597733552455902 614
       .    . .25368568301200867 .46707342419028286 615
       .    . .25779280066490173 .48042078977823255 616
       .    .  .2754182815551758  .5092424299418926 617
       .    . .24655579030513763  .4841941967308522 618
       .    . .24788936972618103 .44376743131875995 619
       .    . .28406214714050293 .46918832257390014 620
       .    .  .2777276337146759 .43159289249777794 621
       .    . .27562543749809265 .44358178663253783 622
       .    . .29391369223594666  .4303132596313953 623
       .    .  .3620969355106354  .5314172388911247 624
       .    . .27849045395851135  .4350079718232155 625
       .    .  .2993468642234802 .43692328178882595 626
       .    . .29546689987182617   .454231461852789 627
       .    . .29740145802497864  .4591437228918076 628
       .    . .30956166982650757  .4705439875423908 629
       .    .  .2841648459434509 .43307311537861826 630
       .    . .28873422741889954  .4410601352155209 631
       .    . .26772990822792053 .40468358850479125 632
       .    . .26939791440963745  .4275408295691013 633
       .    .  .2789442837238312 .41895435905456546 634
       .    . .27547159790992737 .42252303445339207 635
       .    .  .2952445447444916 .45622935092449196 636
       .    .  .3321569859981537  .4966851056218147 637
       .    . .26693618297576904  .4219348928332329 638
       .    .   .287500262260437  .4490783230662346 639
       .    .  .2720051109790802 .43300121307373046 640
       .    .  .2538789212703705  .4258961343169212 641
       .    .  .2665243446826935  .4545821294784546 642
       .    . .23473455011844635  .4291432276368142 643
      end
      and my code is
      Code:
      twoway (line _Y_treated _time, lcolor(black)) (line _Y_synthetic _time, lpattern(dash) lcolor(black)), ///
      ytitle("Garbage") xtitle("Time") xline(`=tm(2010m5)', lpattern(shortdash) lcolor(black)) xla(480(60)720, "%tm")
      with error message
      Code:
      . twoway (line _Y_treated _time, lcolor(black)) (line _Y_synthetic _time, lpattern(dash) lcolor(black)), ///
      > ytitle("Garbage") xtitle("Time") xline(`=tm(2010m5)', lpattern(shortdash) lcolor(black)) xla(480(60)720, "%tm")         
      option "%tm  not allowed
      r(198);
      Any suggestions? Thanks.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        Dear Nick, I found that the following code works (with same data).
        Code:
        twoway (line _Y_treated _time, lcolor(black)) (line _Y_synthetic _time, lpattern(dash) lcolor(black)), ///
        ytitle("Garbage") xtitle("Time") xline(`=tm(2010m5)', lpattern(shortdash) lcolor(black)) xla(540(60)660, format(%tm))
        Click image for larger version

Name:	synth_garbage1.png
Views:	1
Size:	121.2 KB
ID:	1524584


        1. But now my question is that I want only year (not year and month) in the axis, and how can I do that? 2. Is there any way to specify the year and month of the vertical dashed line? Thanks.
        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment


        • #5
          Again, I found that the following code can generate desired x-axis label.
          Code:
          twoway (line _Y_treated _time, lcolor(black)) (line _Y_synthetic _time, lpattern(dash) lcolor(black)), ///
          ytitle("Garbage") xtitle("Time") xline(`=tm(2010m5)', lpattern(shortdash) lcolor(black)) xla(540(12)684, format(%tmCY))
          Click image for larger version

Name:	garbage.png
Views:	1
Size:	126.7 KB
ID:	1524593
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            Indeed. Sorry about forgetting the explicit format() -- which is documented and which I have used many times myself....

            I advise against redundant axis titles like "Time". A reader who doesn't understand what 2005 ... 2017 mean won't understand anything else in the presentation or paper.
            Last edited by Nick Cox; 14 Nov 2019, 02:56.

            Comment


            • #7
              Dear Nick, Thanks. I agree with your suggestion.
              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment

              Working...
              X