Announcement

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

  • Fitting synthetic control

    Hello, folks. I'm finding it hard to fit my synthetic control in STATA.
    I'm evaluating a public security policy that happens in RS state since 2019, especially its impact for reducing homicides.
    I'm using a panel dataset from 2012 to 2021 and have the following covariates: prision population, gini, public security expenditures, GDP, population, average income in state, percentage of black population, and unemployment. My data is yearly, all of it for 26 units of control, and no missing data. My code is, respectively:

    synth hom popp gini osp pib pop salmed negro ocup, trunit(23) trperiod(2018) xperiod(2012, 2013, 2014, 2015, 2016, 2017, 2018) figure nested

    However, the fit is not good. Literature usually uses the covariates above. Am I missing something? My dataset is attached.
    Thanks!
    Attached Files
    Last edited by Edison Jr; 16 Aug 2022, 07:38.

  • #2
    Hi Edison,

    I would rather advise you to post an excerpt of your data using
    Code:
    ssc install dataex
    as per the FAQs.

    On another note, talking of synthetic control, you may want to check out a few other community-contributed commands as well, e.g. Greathouse's (2022) scul or sdid.

    But this depends on your data and your objectives.

    Also, what do you mean specifically by a poor fit?

    Comment


    • #3
      Maxence Morlet Thank you! Although I'm afraid I would never recommend the use of scul in this situation. scul demands a reasonable time period to learn the pre-intervention process.

      7 periods......... it isn't "illegal" (e.g., scul will likely still run the estimates), but I wouldn't trust those estimates as far as I can throw them. Much too short a pre-intervention period. sdid may behave better with shorter pre-intervention time series, but that's for Daniel PV to comment on.


      By the looks of it you're studying Brazil. Rio Grande do Sul. Where did you get this dataset from? Is there a longer pre-intervention time series you can get? Edison Jr


      EDIT

      So I fed it to SCUL really quickly and here's what I got
      Code:
      Optimization took 0.07 minutes
      
      ------------------------------------------
      Relative  |
      Time to   |
      Event     |             RS  Counterfactual
      ----------+-------------------------------
             -7 |           2382        2423.546
             -6 |           2322       2384.6373
             -5 |           2724       2715.9316
             -4 |           2944       2943.8266
             -3 |           3225       3186.8597
             -2 |           3316        3273.527
             -1 |           2699       2683.6719
              0 |           2184       2382.0291
              1 |           1930       2480.8972
              2 |           1869       2343.6746
      ------------------------------------------
      
      Collection: default
            Rows: rowname
         Columns: colname
         Table 1: 5 x 1
      
      ------------
         | Weights
      ---+--------
      BA |   0.074
      RN |   0.009
      SC |   1.898
      SE |   0.623
      TO |   0.036
      ------------
      My code (updated from the SSC version, not public) gives us
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int(ano hom23) double cf float(relative diff_ te_ub te_lb cf_ub cf_lb)
      2012 2382  2423.545985730575 -7  -41.54599   227.6666  -310.7586         .         .
      2013 2322 2384.6372897909255 -6  -62.63729   206.5753  -331.8499         .         .
      2014 2724  2715.931578666573 -5   8.068421    277.281 -261.14417         .         .
      2015 2944 2943.8266275503256 -4  .17337245  269.38596  -269.0392         .         .
      2016 3225  3186.859660450754 -3   38.14034   307.3529 -231.07225         .         .
      2017 3316  3273.526979794116 -2   42.47302   311.6856 -226.73956         .         .
      2018 2699 2683.6718780167325 -1  15.328122   284.5407 -253.88446 2937.5564  2399.131
      2019 2184  2382.029110309313  0  -198.0291   71.18347  -467.2417  2849.271 2310.8457
      2020 1930 2480.8971802768474  1 -550.89716 -281.68457  -820.1097  3301.007 2199.2126
      2021 1869   2343.67459169861  2  -474.6746   -205.462  -743.8871  3087.562 2138.2126
      end
      format %ty ano
      label var ano "Ano (2012-2021)"
      label var hom23 "RS"
      label var cf "Counterfactual"
      
      tsline hom cf, legend(ring(0) pos(11)) tli(2019, lpat(dash) lwidth(thin) lcol("170 19 15"))
      I guess it isn't bad........... but I'd still want more data. My fit looks pretty good, no?

      Other EDIT:
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int ano float hompm23 double cf float(relative diff_ te_ub te_lb cf_ub cf_lb)
      2012 .21654545 .21726017069409742 -7  -.000714723   .01522538 -.016654827         .         .
      2013  .2110909 .21344510090025004 -6 -.0023541935   .01358591 -.018294297         .         .
      2014 .24763636  .2466069266650463 -5  .0010294362   .01696954 -.014910667         .         .
      2015 .26763636  .2677717725265082 -4 -.0001354138   .01580469 -.016075516         .         .
      2016  .2931818  .2922520480959891 -3  .0009297587  .016869862 -.015010345         .         .
      2017  .3014545 .30053985968213115 -2  .0009146844  .016854787  -.01502542         .         .
      2018 .24536364  .2450331869209783 -1  .0003304509  .016270554 -.015609653 .26064283 .22876263
      2019 .19854546 .20004257399324976  0  -.001497118  .014442985 -.017437221  .2174798  .1855996
      2020 .17545454  .2096137391996128  1    -.0341592 -.018219095   -.0500993 .25971305 .19139464
      2021  .1699091 .19647409338568855  2  -.026565004   -.0106249  -.04250511  .2389792  .1858492
      end
      format %ty ano
      label var ano "Ano (2012-2021)" 
      label var hompm23 "RS" 
      label var cf "Counterfactual" 
      
      tsset ano, y
      
      tsline hom cf, legend(ring(0) pos(11)) tli(2019, lpat(dash) lwidth(thin) lcol("170 19 15"))
      My results when using homicides per million as the outcome. SC is a donor, and since SC is next door to RS, this is good to hear since it implies that they share similar common factors which might drive the GDP of homicides.
      Last edited by Jared Greathouse; 16 Aug 2022, 15:45.

      Comment


      • #4
        I had way too much time on my hands. So, I grabbed a longer time series from wikipedia
        Code:
        cls
        
        
        clear
        
        python:
        
        import pandas as pd # library for data analysis
        
        url='https://en.wikipedia.org/wiki/List_of_Brazilian_states_by_murder_rate'
        
        
        table = pd.read_html(url)[3]
        
        print (table.to_csv())
        
        table.to_csv('crime.csv', sep=',')
        
        end
        
        import delimited "E:\Test\crime.csv"
        
        rename stateregion id
        
        drop v18
        
        foreach v of varlist v3-v17 {
           local x : variable label `v'
           rename `v' taxahom`x'
        }
        
        greshape long taxahom, i(v1) j(year)
        
        egen uid = group(id), label(id)
        
        drop id v1
        
        rename uid id
        
        order id year, first
        Which gives us the following
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float id long year float taxahom
         1 1998 21.2
         1 1999  9.7
         1 2000 19.4
         1 2001 21.2
         1 2002 25.7
         1 2003 22.5
         1 2004 18.7
         1 2005 18.7
         1 2006 22.6
         1 2007 18.9
         1 2008 19.6
         1 2009   22
         1 2010 23.3
         1 2011 22.5
         1 2012 27.5
         3 1998 38.7
         3 1999 43.9
         3 2000 32.5
         3 2001 36.9
         3 2002   35
         3 2003 35.5
         3 2004 31.3
         3 2005   33
         3 2006   33
         3 2007 26.9
         3 2008 34.4
         3 2009 30.5
         3 2010 40.2
         3 2011 30.4
         3 2012 35.9
         4 1998 21.3
         4 1999 20.4
         4 2000 19.8
         4 2001 16.7
         4 2002 17.3
         4 2003 18.5
         4 2004 16.9
         4 2005 18.5
         4 2006 21.1
         4 2007   21
         4 2008 24.8
         4 2009   27
         4 2010 31.5
         4 2011 36.4
         4 2012 36.7
        20 1998 13.3
        20 1999 10.8
        20 2000   13
        20 2001 15.1
        20 2002 18.4
        20 2003   21
        20 2004 22.7
        20 2005 27.6
        20 2006 29.2
        20 2007 30.4
        20 2008 39.2
        20 2009 40.3
        20 2010 47.5
        20 2011   40
        20 2012 41.7
        26 1998 38.3
        26 1999 33.5
        26 2000 33.8
        26 2001 40.1
        26 2002 42.3
        26 2003 38.4
        26 2004   38
        26 2005   36
        26 2006 37.7
        26 2007 27.4
        26 2008 32.1
        26 2009 35.6
        26 2010 35.6
        26 2011 28.4
        26 2012 32.9
        27 1998 50.6
        27 1999 57.7
        27 2000 39.5
        27 2001 31.7
        27 2002 34.9
        27 2003 29.7
        27 2004 22.6
        27 2005   24
        27 2006 27.3
        27 2007 27.9
        27 2008 25.4
        27 2009 27.8
        27 2010 28.5
        27 2011 20.6
        27 2012 35.4
        33 1998 12.3
        33 1999   13
        33 2000 15.5
        33 2001 18.8
        33 2002 14.9
        33 2003 18.3
        33 2004 16.4
        33 2005 15.5
        33 2006 17.7
        33 2007 16.5
        33 2008 18.1
        33 2009   22
        33 2010 23.5
        33 2011 25.5
        33 2012 26.2
        17 1998 19.7
        17 1999 17.7
        17 2000 18.6
        17 2001 19.9
        17 2002 21.7
        17 2003 22.9
        17 2004 22.6
        17 2005 25.1
        17 2006   27
        17 2007   26
        17 2008 32.1
        17 2009 33.8
        17 2010 38.8
        17 2011 35.1
        17 2012 37.3
         2 1998 17.8
         2 1999 20.3
         2 2000 25.6
         2 2001 29.3
         2 2002 34.3
         2 2003 35.7
         2 2004 35.1
         2 2005 40.2
         2 2006   53
         2 2007 59.6
         2 2008 60.3
         2 2009 59.3
         2 2010 66.8
         2 2011 72.2
         2 2012 78.6
         5 1998  9.7
         5 1999  6.8
         5 2000  9.4
         5 2001 11.9
         5 2002   13
         5 2003   16
         5 2004 16.6
         5 2005 20.4
         5 2006 23.5
         5 2007 25.7
         5 2008 32.9
         5 2009 36.8
         5 2010 40.4
         5 2011 49.7
         5 2012 58.9
         7 1998 13.4
         7 1999 15.6
         7 2000 16.5
         7 2001 17.2
         7 2002 18.9
         7 2003 20.1
         7 2004   20
         7 2005 20.9
         7 2006 21.8
         7 2007 23.2
         7 2008   24
         7 2009 25.4
         7 2010 31.9
         7 2011 32.7
         7 2012 44.6
        12 1998    5
        12 1999  4.6
        12 2000  6.1
        12 2001  9.4
        12 2002  9.9
        12 2003   13
        12 2004 11.7
        12 2005 14.8
        12 2006   15
        12 2007 17.4
        12 2008 19.7
        12 2009 21.8
        12 2010 23.2
        12 2011 28.7
        12 2012   35
        19 1998 13.5
        19 1999   12
        19 2000 15.1
        19 2001 14.1
        19 2002 17.4
        19 2003 17.6
        19 2004 18.6
        19 2005 20.6
        19 2006 22.6
        19 2007 23.6
        19 2008 27.3
        19 2009 33.7
        19 2010 38.8
        19 2011 47.7
        19 2012 52.1
        21 1998 72.9
        21 1999 63.4
        21 2000   54
        21 2001 58.7
        21 2002 54.8
        21 2003 55.3
        21 2004 50.7
        21 2005 51.2
        21 2006 52.7
        21 2007 53.1
        21 2008 50.7
        21 2009 44.9
        21 2010 39.3
        21 2011 35.1
        21 2012 30.1
        22 1998  5.2
        22 1999  4.8
        22 2000  8.2
        22 2001  9.7
        22 2002 10.9
        22 2003 10.8
        22 2004 11.8
        22 2005 12.8
        22 2006 14.4
        22 2007 13.2
        22 2008 17.4
        22 2009 25.7
        22 2010 36.8
        22 2011 52.7
        22 2012 68.2
        23 1998  8.5
        23 1999  8.5
        23 2000    9
        23 2001 11.2
        23 2002 10.6
        23 2003 14.2
        23 2004 11.7
        23 2005 13.6
        23 2006 14.8
        23 2007 19.3
        23 2008 23.2
        23 2009 28.2
        23 2010   33
        23 2011 40.6
        23 2012 48.7
        29 1998 10.4
        29 1999 19.7
        29 2000 23.3
        29 2001 29.3
        29 2002 29.7
        29 2003 25.2
        29 2004 24.4
        29 2005   25
        29 2006 29.8
        29 2007 25.9
        29 2008 28.7
        29 2009 32.8
        29 2010 40.9
        29 2011 47.4
        29 2012 55.8
        31 1998 18.5
        31 1999 17.5
        31 2000 19.3
        31 2001 21.9
        31 2002 22.4
        31 2003   24
        31 2004 23.2
        31 2005 25.4
        31 2006 27.9
        31 2007 29.6
        31 2008 32.1
        31 2009 35.4
        31 2010 41.5
        31 2011 48.3
        31 2012 52.4
        10 1998 65.4
        10 1999 52.5
        10 2000 46.8
        10 2001 46.7
        10 2002 51.2
        10 2003 50.5
        10 2004 49.4
        10 2005 46.9
        10 2006 51.2
        10 2007 53.6
        10 2008 56.4
        10 2009 57.2
        10 2010 51.5
        10 2011 47.4
        10 2012 25.3
        15 1998  8.6
        15 1999  8.9
        15 2000 11.5
        15 2001 12.9
        15 2002 16.2
        15 2003 20.6
        15 2004 22.6
        15 2005 21.9
        15 2006 21.3
        15 2007 20.8
        15 2008 19.5
        15 2009 18.5
        15 2010 18.4
        15 2011 17.5
        15 2012 15.8
        25 1998 55.3
        25 1999 52.5
        25 2000   51
        25 2001 50.5
        25 2002 56.5
        25 2003 52.7
        25 2004 49.2
        25 2005 46.1
        25 2006 45.8
        25 2007 40.1
        25 2008   34
        25 2009 31.7
        25 2010 33.1
        25 2011 28.3
        25 2012 20.3
        32 1998 48.7
        32 1999 44.1
        32 2000 42.2
        32 2001 41.8
        32 2002   38
        32 2003 35.9
        32 2004 28.6
        32 2005 21.6
        32 2006 19.9
        32 2007   15
        32 2008 14.9
        32 2009 15.3
        32 2010 14.1
        32 2011 13.5
        32 2012 11.1
        30 1998 43.3
        30 1999 37.4
        30 2000 36.6
        30 2001 36.6
        30 2002 36.8
        30 2003 36.1
        30 2004 32.1
        30 2005 27.6
        30 2006 26.7
        30 2007   23
        30 2008 21.6
        30 2009 21.1
        30 2010 20.5
        30 2011 19.9
        30 2012 18.1
        18 1998 17.6
        18 1999 18.1
        18 2000 18.5
        18 2001   21
        18 2002 22.7
        18 2003 25.5
        18 2004 28.1
        18 2005   29
        18 2006 29.8
        18 2007 29.6
        18 2008 32.6
        18 2009 34.6
        18 2010 34.3
        18 2011 31.7
        18 2012 32.7
        24 1998 15.3
        24 1999 15.3
        24 2000 16.3
        24 2001 17.9
        24 2002 18.3
        24 2003 18.1
        24 2004 18.5
        24 2005 18.6
        24 2006 17.9
        24 2007 19.6
        24 2008 21.8
        24 2009 20.4
        24 2010 19.2
        24 2011 19.2
        24 2012 21.9
        28 1998  7.9
        28 1999  7.5
        28 2000  7.9
        28 2001  8.4
        28 2002 10.3
        28 2003 11.6
        28 2004 11.1
        28 2005 10.5
        28 2006   11
        28 2007 10.4
        28 2008   13
        28 2009 13.1
        28 2010 13.2
        28 2011 12.6
        28 2012 10.8
         8 1998 14.7
         8 1999 14.7
         8 2000 15.3
         8 2001 17.1
         8 2002 18.3
         8 2003 19.5
         8 2004 20.6
         8 2005 20.8
         8 2006 20.9
         8 2007 21.4
         8 2008   24
         8 2009 24.3
         8 2010 23.6
         8 2011 22.4
         8 2012   24
         9 1998 37.4
         9 1999 36.7
         9 2000 37.5
         9 2001 36.9
         9 2002 34.7
         9 2003 39.1
         9 2004 36.5
         9 2005 31.9
         9 2006 32.3
         9 2007 33.5
         9 2008 34.1
         9 2009 32.6
         9 2010 28.4
         9 2011 22.4
         9 2012 18.9
        11 1998 13.4
        11 1999 16.5
        11 2000 20.2
        11 2001 21.5
        11 2002 24.5
        11 2003 23.7
        11 2004 26.4
        11 2005 24.9
        11 2006 24.6
        11 2007 24.4
        11 2008   30
        11 2009 30.2
        11 2010   32
        11 2011 28.4
        11 2012 24.3
        13 1998 36.3
        13 1999 34.7
        13 2000 39.8
        13 2001 38.5
        13 2002   37
        13 2003   35
        13 2004 32.1
        13 2005 32.4
        13 2006 31.5
        13 2007 30.7
        13 2008 31.8
        13 2009 33.3
        13 2010 30.6
        13 2011 26.3
        13 2012 24.1
        14 1998 33.5
        14 1999 28.2
        14 2000   31
        14 2001 29.3
        14 2002 32.4
        14 2003 32.7
        14 2004 29.6
        14 2005 27.7
        14 2006 29.5
        14 2007   30
        14 2008 29.5
        14 2009 30.8
        14 2010 26.7
        14 2011   24
        14 2012 22.1
        16 1998 26.1
        16 1999   26
        16 2000 29.4
        16 2001 29.3
        16 2002 30.4
        16 2003 30.5
        16 2004   30
        16 2005 28.2
        16 2006 28.3
        16 2007 28.4
        16 2008 31.1
        16 2009 32.6
        16 2010 31.7
        16 2011 27.1
        16 2012 22.3
         6 1998 25.9
         6 1999 26.2
         6 2000 26.7
         6 2001 27.8
         6 2002 28.5
         6 2003 28.9
         6 2004   27
         6 2005 25.8
         6 2006 26.3
         6 2007 25.2
         6 2008 26.4
         6 2009 26.9
         6 2010 27.5
         6 2011 27.1
         6 2012   29
        end
        label values id id
        label def id 1 "Acre", modify
        label def id 2 "Alagoas", modify
        label def id 3 "Amapá", modify
        label def id 4 "Amazonas", modify
        label def id 5 "Bahia", modify
        label def id 6 "Brazil", modify
        label def id 7 "Ceará", modify
        label def id 8 "Center-West", modify
        label def id 9 "Distrito Federal", modify
        label def id 10 "Espírito Santo", modify
        label def id 11 "Goiás", modify
        label def id 12 "Maranhão", modify
        label def id 13 "Mato Grosso", modify
        label def id 14 "Mato Grosso do Sul", modify
        label def id 15 "Minas Gerais", modify
        label def id 16 "North", modify
        label def id 17 "Northeast", modify
        label def id 18 "Paraná", modify
        label def id 19 "Paraíba", modify
        label def id 20 "Pará", modify
        label def id 21 "Pernambuco", modify
        label def id 22 "Piauí", modify
        label def id 23 "Rio Grande do Norte", modify
        label def id 24 "Rio Grande do Sul", modify
        label def id 25 "Rio de Janeiro", modify
        label def id 26 "Rondônia", modify
        label def id 27 "Roraima", modify
        label def id 28 "Santa Catarina", modify
        label def id 29 "Sergipe", modify
        label def id 30 "South", modify
        label def id 31 "Southeast", modify
        label def id 32 "São Paulo", modify
        label def id 33 "Tocantins", modify
        label var id "group(id)"
        I would then stack your homicide estimates on top of mine, and use scul to learn the pre-intervention process and forecast the counterfactual like that.


        No covariates, not needed. I'll demonstrate in a few.

        Comment


        • #5
          Thank you very much, Jared Greathouse , you're helping very much!

          Comment


          • #6
            Yeah I can send you my paper if you'd like. You can use scul, but my advice is to really read the help file and my paper before doing so. So just lemme know and I'll email you Edison Jr

            Comment


            • #7
              Jared Greathouse Please, send me it. I've just sent you a private message and an e-mail. Thanks!

              Comment


              • #8
                I am struggling with SCM. I am having research on "Devaluation of Currency and Export Performance in Bangladesh". Thriving to get SCM for most common graphics even! Suggestions are welcome. Thank You.
                Attached Files

                Comment


                • #9
                  I am struggling with SCM
                  How?

                  Thriving to get SCM for most common graphics even!
                  Huh? I don't understand.

                  Comment

                  Working...
                  X