Announcement

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

  • Graph with lines in same gray color

    Hi everyone,


    Currently, I am working with a panel data set with countries and annual data from 1970 onwards in which the main variable is ton-kilometers freight transported by road.
    I would like to get a line graph (xtline for instance) in which the country that gets treatment (Poland, country_id=70) gets a different color, navy, and all the control countries are having the same gray color. I made a dummy variable "donor" which equals 1 if the country is part of the control group.
    I have read a lot about creating graphs with different colors for groups, however the problem that I keep encountering is that I want to combine a graph of two different groups (first sorted by country and then by donor or not).

    I was thinking about creating a graph with all the lines for road_tkm of the control countries first (all in a gray color) and combining it with a graph of the treatment country. However, I can't find the code for giving all the lines of the donor pool one/gray color (but still showing the individual trends).
    Does someone know what I can do? The final legend should only contain a gray bar with "donor countries" and a navy one for "Poland".


    Here is a sample of my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte country_id float donor double road_tkm
    70 0           17930
    70 0           44546
    70 0          136490
    70 0           45365
    70 0           24549
    70 0           36592
    70 0           36577
    70 0           15761
    70 0          377778
    70 0           75023
    70 0           32596
    70 0          159527
    70 0          191484
    70 0           63688
    70 0           38448
    70 0          218888
    70 0           42601
    70 0           40277
    70 0           69542
    70 0          119740
    70 0          233310
    70 0           34024
    70 0           36779
    70 0           44088
    70 0           40744
    70 0           28515
    70 0          303560
    70 0           36847
    70 0           77228
    70 0          348559
    70 0          259708
    70 0           85989
    70 0          174223
    70 0          214204
    70 0           51200
    70 0          273107
    70 0          262860
    70 0           39240
    70 0           37340
    70 0           70452
    70 0           42335
    70 0           21393
    70 0           39641
    70 0           35472
    70 0           40293
    70 0          395311
    70 0          461582
    70 0           37183
    70 0           80318
    70 0          110481
    70 0           56513
     6 1 146508.69995977
     6 1   192453.589541
     6 1 180106.67735693
     6 1 160123.95377196
     6 1 89198.667941911
     6 1 89382.555090445
     6 1 51603.792959022
     6 1 207347.92052656
     6 1 93438.219018693
     6 1 125843.81520744
     6 1 58115.430934599
     6 1 209839.86417566
     6 1   164194.685136
     6 1 224152.10290141
     6 1 186081.65153941
     6 1 43022.430944004
     6 1  108376.1883243
     6 1 89107.403303688
     6 1 216247.20344118
     6 1 75749.030108977
     6 1  133173.2753314
     6 1           24808
     6 1 33482.496367013
     6 1  171860.5919496
     6 1 81967.942407818
     6 1 202152.21394323
     6 1 70888.468661318
     6 1 65793.907557193
     6 1  202874.0275468
     6 1  47642.92774081
     6 1           26530
     6 1 180754.90115588
     6 1 204532.44421558
     6 1  34639.63109173
     6 1 118878.00796988
     6 1 155094.31411296
     6 1 92935.455291299
     6 1 131638.94369203
     6 1 76233.776958745
     6 1 37417.069348727
     6 1 30391.898404295
     6 1 112713.58262185
     6 1 42280.276987106
     6 1 218903.20857613
     6 1 139142.51983372
     6 1 103624.40978427
     6 1 63186.290615772
     6 1 95937.290551047
     6 1 199992.59777756
    end
    xtline road_tkm if donor==1, lc(gs7) overlay

    This is the simple command I tried for the first graph, but somehow STATA does not understand why I want to use only one color for all the lines (what I can understand, haha).


    Thank you in advance!

  • #2
    I presume you're using SCM and you've done placebo studies. See my query answered by Maarten Buis

    https://www.statalist.org/forums/for...ing-each-other

    Comment


    • #3
      Thank you, Jared, for your reply. It is correct I am using SCM, however I want to show that the Convex Hull condition holds. So what I want to do is showing the trend of my treated unit in contrast with the trends of the donor pool countries.


      However, your query is very helpful for my analysis, so thanks for sharing

      Comment


      • #4
        You can still do that with the code I've given. I'll post an example later on when I'm home in an hour or two Harina Peternella

        Comment


        • #5
          I would not approach that need with xtline.

          Here is some technique.

          Code:
          webuse grunfeld, clear
          
          line invest year if company != 7, ysc(log) lc(gs8) c(L) || line invest year if company == 7, lc(navy) lw(thick) ysc(log) scheme(s1color) legend(order(2 "Company 7") ring(0) pos(5)) yla(1 10 100 1000, ang(h))
          Click image for larger version

Name:	company7.png
Views:	1
Size:	57.9 KB
ID:	1679602

          Comment


          • #6
            My approach was pretty similar.
            Code:
            u "http://fmwww.bc.edu/repec/bocode/s/scul_basque.dta", clear
            
            qui xtset
            local lbl: value label `r(panelvar)'
            
            loc unit ="Basque Country (Pais Vasco)":`lbl'
            
            
            loc int_time = 1975
            
            qui xtset
            cls
            
            g treat = cond(`r(panelvar)'==`unit',1,0)
            
            labvars treat gdp "Terrorism" "GDP per Capita"
            
            line gdp year if !treat,           ///
                connect(L)                                   ///
                lcolor(gs6)                        ///
                scheme(gg_tableau)                        ///
                lwidth(thin)                                 ///
                 ||                                          ///
                   line gdp year if treat,             ///
                lcol(navy) lwidth(thick) ///
                legend(order(1 "Donors" 2 "Basque") pos(5) ring(0))          ///         
                xli(1975, lcol(blue) lwidth(medthick) lpat(solid)) ///
                yti("GDP per Capita") xti(Year)
            Note that I use Asjad Naqvi's gg_tableau from his Stata Schemes, as well as labvars from ssc (which should really jut by now be a Stata native command). A similar approach can be used with the selected donor pool, just restrict your graph to the treated unit and the donors selected by scm, as I do in Figure 5 here. And, since we're discussing SCM and Convex Hulls, just sort of note that it may not make sense to use the convex hull assumptions. I argue for this in my paper pretty heavily, that allowing for negative weights that don't add to 1 can oftentimes improve predictions as well as pre-intervention fit. Of course, I'm not the only one to point this out and demonstrate it, leading econometricians and computer scientists who are much smarter than me at this have pointed it out and made the case too.

            Comment


            • #7
              Thank you very much. I tried something similar as Nick posted, but now I understand what I did wrong.

              Jared, I really appreciate your additional note and the link to these papers. I think I agree with you and it will be nice to use them as references.

              Comment

              Working...
              X