Announcement

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

  • Plotting graphs related to synth (synthetic control)

    Click image for larger version

Name:	gráfico 6.jpg
Views:	0
Size:	0
ID:	1680600 Folks, I’m trying to plot some graphs related to command synth in Stata, but I’m not succeeding…

    I want to create with my dataset some graphs of the following paper:

    Abadie, A., Diamond, A., & Hainmueller, J. (2015). Comparative Politics and the Synthetic Control Method. American Journal of Political Science, 59(2), 495–510. https://doi.org/10.1111/ajps.12116

    Graphs:
    Click image for larger version

Name:	gráfico 3.jpg
Views:	1
Size:	21.3 KB
ID:	1680598



    «FIGURE 3 Per Capita GDP Gap between West Germany an» (Abadie et al., 2015, p. 504)



    «FIGURE 6 Leave-One-Out Distribution of the Synthetic Control for West Germany» (Abadie et al., 2015, p. 506).

    My dataset is a panel and has 27 states, 10 years (2012 to 2021), my dependent variable is hompm (homicides per 100.000 hab.), my data is annual, and treatment happended to RS state (id 23) in February/2019.

    I am creating the synthetic RS state (id 23) by using the code below:

    synth hompm hompm(2012) hompm(2013) hompm(2014) hompm(2015) hompm(2016) hompm(2017) hompm(2018) pibpc ocuppc popppc osppc salmed gini pop pp1624, trunit(23) trperiod(2019) fig

    I really have no idea on how to plot graphs in Figure 3 and 6… Could you help me, please?

    I can send you my dataset, if necessary.

    Thanks in advance!
    Last edited by Edison Jr; 03 Sep 2022, 13:07.

  • #2
    I'm the person who's best equipped to answer you on this forum, but before I answer anything, I'm gonna need a dataset to work with. Truthfully, I could answer you right now, but I don't wanna speculate, I wanna see your real actual dataset with dataex, please.

    Also, can you please explain to me why you need to include a lag of the outcome in every single year pre-intervention?

    As a matter of fact, please present the results of
    Code:
    dataex id year hompm, count(280) v
    EDIT: In the future, please note that synth is a user written command which you're asked to specify. I know it is, but other people won't know, so please, please, always give data examples AND specify that you're working with non-native Stata commands so others can learn from this post, too
    Last edited by Jared Greathouse; 03 Sep 2022, 13:08.

    Comment


    • #3
      Hello Jared!

      input byte id int ano float hompm
      1 2012 27.41221
      1 2013 30.13666
      1 2014 29.363335
      1 2015 27.00641
      1 2016 44.44787
      1 2017 62.19722
      1 2018 47.05124
      1 2019 36.85079
      1 2020 35.663578
      1 2021 21.061314
      2 2012 63.9375
      2 2013 65.09091
      2 2014 63.18182
      2 2015 52.9697
      2 2016 53.52941
      2 2017 53.32353
      2 2018 43.66667
      2 2019 33.78788
      2 2020 35.588234
      2 2021 33.35294
      3 2012 37.333332
      3 2013 31.342106
      3 2014 31.79487
      3 2015 37.74359
      3 2016 36.3
      3 2017 40.82927
      3 2018 37.609756
      3 2019 38.82927
      3 2020 27.037283
      3 2021 39.41861
      4 2012 36.215183
      4 2013 30.61241
      4 2014 34.091877
      4 2015 38.21678
      4 2016 48.70285
      4 2017 48.01171
      4 2018 51.35661
      4 2019 42.68497
      4 2020 41.28571
      4 2021 53.32647
      5 2012 43.91429
      5 2013 37.96
      5 2014 40.34667
      (...)

      Comment


      • #4
        Here is my dataset.
        Attached Files

        Comment


        • #5
          No no no, I specifically asked for
          Code:
          dataex id int ano hompm, v count(270)
          I want the results of this. Your dataex should return 270 observations, so that's what I'd like, please. Edison Jr

          Comment


          • #6
            . dataex id int ano hompm, v count(270)
            int not allowed

            Comment


            • #7
              My apologies,
              Code:
              dataex id ano hompm trat, v count(270)

              Comment


              • #8
                Dataset annex is correct now.

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input byte id int ano float hompm byte trat
                 1 2012  27.41221 0
                 1 2013  30.13666 0
                 1 2014 29.363335 0
                 1 2015  27.00641 0
                 1 2016  44.44787 0
                 1 2017  62.19722 0
                 1 2018  47.05124 0
                 1 2019  36.85079 0
                 1 2020 35.663578 0
                 1 2021 21.061314 0
                 2 2012   63.9375 0
                 2 2013  65.09091 0
                 2 2014  63.18182 0
                 2 2015   52.9697 0
                 2 2016  53.52941 0
                 2 2017  53.32353 0
                 2 2018  43.66667 0
                 2 2019  33.78788 0
                 2 2020 35.588234 0
                 2 2021  33.35294 0
                 3 2012 37.333332 0
                 3 2013 31.342106 0
                 3 2014  31.79487 0
                 3 2015  37.74359 0
                 3 2016      36.3 0
                 3 2017  40.82927 0
                 3 2018 37.609756 0
                 3 2019  38.82927 0
                 3 2020 27.037283 0
                 3 2021  39.41861 0
                 4 2012 36.215183 0
                 4 2013  30.61241 0
                 4 2014 34.091877 0
                 4 2015  38.21678 0
                 4 2016  48.70285 0
                 4 2017  48.01171 0
                 4 2018  51.35661 0
                 4 2019  42.68497 0
                 4 2020  41.28571 0
                 4 2021  53.32647 0
                 5 2012  43.91429 0
                 5 2013     37.96 0
                 5 2014  40.34667 0
                 5 2015     40.08 0
                 5 2016  47.80667 0
                 5 2017  49.91333 0
                 5 2018  45.24667 0
                 5 2019     40.78 0
                 5 2020  41.40667 0
                 5 2021     43.16 0
                 6 2012  44.66279 0
                 6 2013  50.82954 0
                 6 2014  52.56818 0
                 6 2015  46.77528 0
                 6 2016  40.46667 0
                 6 2017  60.36666 0
                 6 2018  53.84615 0
                 6 2019  26.56044 0
                 6 2020  45.43478 0
                 6 2021 37.260868 0
                 7 2012 36.692307 0
                 7 2013 29.892857 0
                 7 2014 29.068966 0
                 7 2015 25.586206 0
                 7 2016 25.333334 0
                 7 2017 20.333334 0
                 7 2018 17.666666 0
                 7 2019        16 0
                 7 2020        14 0
                 7 2021 11.193548 0
                 8 2012  46.30556 0
                 8 2013  42.68421 0
                 8 2014  41.25641 0
                 8 2015 37.179485 0
                 8 2016     31.75 0
                 8 2017    38.025 0
                 8 2018    29.125 0
                 8 2019    26.075 0
                 8 2020 29.341463 0
                 8 2021 28.268293 0
                 9 2012  45.04839 0
                 9 2013  46.48438 0
                 9 2014  44.41539 0
                 9 2015  45.40909 0
                 9 2016  45.31343 0
                 9 2017  42.66177 0
                 9 2018  38.76812 0
                 9 2019 32.185715 0
                 9 2020 22.239437 0
                 9 2021  18.01389 0
                10 2012  26.52239 0
                10 2013  31.80882 0
                10 2014  35.68116 0
                10 2015 35.333332 0
                10 2016      34.4 0
                10 2017 31.142857 0
                10 2018 28.314285 0
                10 2019        24 0
                10 2020  28.80488 0
                10 2021  28.11111 0
                11 2012    22.815 0
                11 2013  22.46667 0
                11 2014 22.490477 0
                11 2015 21.585714 0
                11 2016 22.009523 0
                11 2017  20.47619 0
                11 2018 16.061905 0
                11 2019 13.780952 0
                11 2020 13.385715 0
                11 2021 13.457143 0
                12 2012     27.32 0
                12 2013  24.23077 0
                12 2014 26.923077 0
                12 2015  23.48148 0
                12 2016  24.85185 0
                12 2017  24.40741 0
                12 2018 21.185184 0
                12 2019 17.535715 0
                12 2020 17.642857 0
                12 2021 17.857143 0
                13 2012  34.64516 0
                13 2013   36.1875 0
                13 2014   42.4375 0
                13 2015 36.454544 0
                13 2016 35.757576 0
                13 2017  33.39394 0
                13 2018 29.088236 0
                13 2019  25.57143 0
                13 2020      28.4 0
                13 2021 24.666666 0
                14 2012  41.33333 0
                14 2013   42.5625 0
                14 2014  42.54321 0
                14 2015  44.81707 0
                14 2016  50.68675 0
                14 2017  54.46429 0
                14 2018  53.27059 0
                14 2019  39.59302 0
                14 2020 32.563217 0
                14 2021 32.534885 0
                15 2012  40.13158 0
                15 2013  39.76923 0
                15 2014  39.76923 0
                15 2015     38.05 0
                15 2016    33.875 0
                15 2017    33.525 0
                15 2018      31.1 0
                15 2019    23.825 0
                15 2020    29.175 0
                15 2021 28.317074 0
                16 2012 37.382023 0
                16 2013  33.95652 0
                16 2014  36.10753 0
                16 2015  41.35484 0
                16 2016  47.30851 0
                16 2017  57.04211 0
                16 2018  44.10526 0
                16 2019   36.1875 0
                16 2020  40.36458 0
                16 2021 35.804123 0
                17 2012  16.40625 0
                17 2013   18.6875 0
                17 2014  22.40625 0
                17 2015   20.3125 0
                17 2016  21.90625 0
                17 2017   19.5625 0
                17 2018 18.757576 0
                17 2019 17.242424 0
                17 2020  21.48485 0
                17 2021  23.72727 0
                18 2012  31.71818 0
                18 2013  26.69091 0
                18 2014  27.09091 0
                18 2015  26.69091 0
                18 2016  28.00909 0
                18 2017  25.08182 0
                18 2018  22.20909 0
                18 2019 19.045454 0
                18 2020 20.733334 0
                18 2021    20.775 0
                19 2012    29.825 0
                19 2013   31.9375 0
                19 2014  35.74375 0
                19 2015 29.811764 0
                19 2016      35.6 0
                19 2017  37.74706 0
                19 2018  37.97647 0
                19 2019 20.888235 0
                19 2020 28.911764 0
                19 2021  27.94118 0
                20 2012    35.125 0
                20 2013  42.55882 0
                20 2014  47.11765 0
                20 2015  45.44118 0
                20 2016  52.97143 0
                20 2017  62.94286 0
                20 2018  52.14286 0
                20 2019  38.45714 0
                20 2020  42.51429 0
                20 2021 36.305557 0
                21 2012    32.875 0
                21 2013 28.411764 0
                21 2014        34 0
                21 2015 33.333332 0
                21 2016  39.05556 0
                21 2017  30.77778 0
                21 2018 26.444445 0
                21 2019 24.833334 0
                21 2020 22.333334 0
                21 2021  26.22222 0
                22 2012  30.66936 0
                22 2013  43.84599 0
                22 2014  31.79484 0
                22 2015  40.14516 0
                22 2016  39.67104 0
                22 2017  47.45176 0
                22 2018  71.80419 0
                22 2019   38.6291 0
                22 2020 33.758385 0
                22 2021 35.543953 0
                23 2012 21.654545 0
                23 2013  21.10909 0
                23 2014 24.763636 0
                23 2015 26.763636 0
                23 2016  29.31818 0
                23 2017 30.145454 0
                23 2018 24.536364 0
                23 2019 19.854546 1
                23 2020 17.545454 1
                23 2021  16.99091 1
                24 2012 12.828125 0
                24 2013 11.954545 0
                24 2014 13.507463 0
                24 2015  14.07353 0
                24 2016  14.26087 0
                24 2017 15.228572 0
                24 2018  11.87324 0
                24 2019 10.652778 0
                24 2020 11.123287 0
                24 2021 10.863013 0
                25 2012  41.85714 0
                25 2013  43.86364 0
                25 2014  49.86364 0
                25 2015  59.22727 0
                25 2016  63.69565 0
                25 2017  57.08696 0
                25 2018  49.26087 0
                25 2019  42.30435 0
                25 2020  42.65217 0
                25 2021  34.47826 0
                26 2012 15.633333 0
                26 2013 13.713636 0
                26 2014 14.061363 0
                26 2015 12.329545 0
                26 2016     10.82 0
                26 2017  10.29111 0
                26 2018  8.097826 0
                26 2019  7.306522 0
                26 2020  9.056521 0
                26 2021  7.542553 0
                27 2012  27.07143 0
                27 2013 23.266666 0
                27 2014      25.4 0
                27 2015 33.533333 0
                27 2016  38.46667 0
                27 2017   34.8125 0
                27 2018    35.625 0
                27 2019      28.5 0
                27 2020        29 0
                27 2021   25.6875 0
                end
                label var id "ID" 
                label var ano "Ano (2012-2021)" 
                label var hompm "Homicídios por 100 mil habitantes" 
                label var trat "Tratamento RS 2019"
                Attached Files

                Comment


                • #9
                  Okay thank you. Here's some code.
                  Code:
                  u "https://www.statalist.org/forums/filedata/fetch?id=1680603", clear
                  cls
                  
                  egen ano = seq(), f(2012) t(2021)
                  
                  // ssc inst labmask, replace
                  
                  labmask id, values(uf)
                  
                  xtset id ano, y
                  
                  keep id hompm ano trat
                  cls
                  
                  // ssc inst scul, replace
                  
                  scul hom, treated(trat) cv(adaptive) obscol(blue) cfcol(red) ///
                  legpos(2) 
                  
                  cls
                  u scul_RS, clear
                  
                  
                  line diff rel, yti(Pointwise treatment effect) tli(0, lpat(dash) lcol(black))
                  This is scul, the synthetic control estimator I wrote. SCUL saves a dataset, in this case called scul_RS. After we estimate the effects as above, at this point it's just a matter of accessing your dataset. In your case, you'd do this with something like
                  Code:
                  synth hompm hompm(2012) hompm(2013) hompm(2014) hompm(2015) hompm(2016) hompm(2017) hompm(2018) ///
                  pibpc ocuppc popppc osppc salmed gini pop pp1624, trunit(23) trperiod(2019) fig keep(RS, replace)
                  And you'd acces the RS dataset, take the difference between the observed and the counterfactual and make the same graph as I do with my code. Your next question is leave one out analyses. Essentially, you exclude the units originally selected by synth to see how robust the results are. The best command that I know that does this is synth2, using its loo option which iteratively leaves out selected donors.

                  Comment


                  • #10
                    My next question though is more to do with your specification. Why choose the specification
                    Code:
                    synth hompm hompm(2012) hompm(2013) hompm(2014) hompm(2015) hompm(2016) hompm(2017) hompm(2018) ///
                    pibpc ocuppc popppc osppc salmed gini pop pp1624, trunit(23) trperiod(2019) fig keep(RS, replace)
                    Why are you lagging the outcome in every single year?

                    Comment


                    • #11
                      Jared Greathouse No, I'm not lagging. Should I?

                      Comment


                      • #12
                        In the SCM literature, we say you "lag" your outcome variables/covariates when you do
                        Code:
                        hompm(2012) hompm(2013) hompm(2014)
                        We'd say you'd lagged it (more like taking its average) at 2012, 2013 and 2014. And all I'm asking you, is why are you using the entire pre-intervention series? This is not advisable .

                        Comment


                        • #13
                          Thanks for the advise. I'm reading the paper!

                          Comment


                          • #14
                            The argument I make in my paper is that choosing lags is arbitrary, and there's no systematic way of going about it. Scul alleviates this concern, and chooses the donors based off how well they predict the treated unit in the pre-intervention period. With scul, you'd just do
                            Code:
                            scul hom, treated(trat)
                            and boom, no fuss, no muss

                            Comment

                            Working...
                            X