Announcement

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

  • #16
    Now Stata tells me

    frac_age_15to59 does not exist as a (numeric) variable in dataset
    Either way, when you plug it into your full dataset, presumably it will run. By the way, how many control units do you have? How many pre-intervention periods do you have?

    Comment


    • #17
      Ok, so we have data from January 2015 up to December 2019, so 59 months, in %tm format.

      We have the treated unit ("Madrid") and 51 other regions, or provincias in Spanish.

      The pre-intervention periods correspond of months up to April 2018. Post-intervention periods go from May 2018 onwards.
      Last edited by Michael Duarte Goncalves; 02 Oct 2024, 07:31.

      Comment


      • #18
        Bueno... In that case, you may be interested in my Forward DID estimator. The paper describing the method is here. Basically, we use Forward Selection to choose the control group for Madrid in this case. Presumably you wish to use SCM because you believe parallel trends does not hold with respect to the full donor pool/control group. Well... FDID posits that PTA may hold, for some control units. It uses an iterative forward selection procedure to pick the best controls. Plus, it does not need covariate data to estimate. For example:

        Code:
        clear *
        
        net from "https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main"
        net install fdid, replace
        
        net get fdid, replace
        
        // install sdid_event from github : https://github.com/DiegoCiccia/sdid/tree/main/sdid_event#github
        
        
        // install sdid from github
        
        // net install sdid, from("https://raw.githubusercontent.com/daniel-pailanir/sdid/master") replace
        
        u "basque.dta", clear
        cls
        
        fdid gdp, tr(treat) gr1opts(title(Forward DID Analysis))
        
        mat l e(results)
        Returns

        Code:
        Forward Difference-in-Differences   |    T0 R2: 0.994  T0 RMSE: 0.078
        -----------------------------------------------------------------------------
              gdpcap |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
        -------------+---------------------------------------------------------------
               treat |  -0.87506    0.02328    37.59    0.000    -0.92069    -0.82943
        -----------------------------------------------------------------------------
        Treated Unit: Basque Country (Pais Vasco)
        FDID selects Cataluna, Aragon, as the optimal donors.
        See Li (2024) for technical details.
        
        
        
        
                     ATT        PATT          SE           t          LB          UB          R2
        FDID  -.87506103  -10.034511   .02328082   37.587203  -.92069061  -.82943146   .99433826
         DID  -.53299738     -6.3615   .15540026   3.4298358  -.86243122  -.20356354       .9796
        In this case, we (naturally) select Catalonia as a control and Aragon. This actually gets better RMSE than the original SCM, which employed many predictor variables. Michael Duarte Goncalves

        Comment


        • #19
          Beautiful, sounds good.

          How could I obtain the beautiful plots that we usually obtain from Synthetic Controls methods using -fdid- package?

          Thanks again for your time!

          Comment


          • #20
            I obtain this error when I ran your shared code:

            Code:
            . fdid gdp, tr(treat) gr1opts(title(Forward DID Analysis))
            Install sdid_event before using fdid.
            r(498);
            
            end of do-file
            
            r(498);
            Code:
            clear *
            
            net from "https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main"
            net install fdid, replace
            
            net get fdid, replace
            
            //  install sdid_event from github : https://github.com/DiegoCiccia/sdid/tree/main/sdid_event#github
            
             net install sdid_event, from("https://github.com/DiegoCiccia/sdid/tree/main/sdid_event#github") replace
             
            // install sdid from github
            
             net install sdid, from("https://raw.githubusercontent.com/daniel-pailanir/sdid/master") replace
            
            u "basque.dta", clear
            cls
            
            fdid gdp, tr(treat) gr1opts(title(Forward DID Analysis))
            
            mat l e(results)

            Comment


            • #21
              The way to do it is by taking advantage of the saved results. So when you run the code above, you can do

              Code:
              mat l e(series)
              which returns
              Code:
              e(series)[43,9]
                         year     gdpcap5       cfdd5   ymeandid5  ymeanfdid5         cf5         te5       ddte5  eventtime5
               r1        1955   3.8531846    3.956224   2.3359621   2.9177022     3.75793   .09525459  -.10303933         -20
               r2        1956   3.9456583   4.0863519     2.46609   3.0678022     3.90803   .03762826  -.14069358         -19
               r3        1957   4.0335617   4.2142215   2.5939598    3.215117   4.0553446  -.02178285  -.18065974         -18
               r4        1958   4.0234219   4.2459626   2.6257007    3.257355   4.0975828  -.07416092  -.22254072         -17
               r5        1959    4.013782   4.2780561   2.6577942   3.2994144   4.1396422  -.12586027  -.26427418         -16
               r6        1960   4.2859184   4.4710188   2.8507569   3.5616252   4.4018531  -.11593468  -.18510039         -15
               r7        1961   4.5743361    4.649334    3.029072   3.8374393   4.6776671  -.10333104  -.07499786         -14
               r8        1962   4.8989574   4.8656874   3.2454255   4.0986147   4.9388423  -.03988494   .03326998         -13
               r9        1963    5.197015   5.0760469    3.455785   4.3477578   5.1879854   .00902956   .12096804         -12
              r10        1964    5.338903   5.1656551   3.5453932   4.4190946   5.2593222   .07958081   .17324784         -11
              r11        1965    5.465153   5.2505326   3.6302707   4.4844689   5.3246965   .14045647   .21462038         -10
              r12        1966   5.5459156   5.3733635   3.7531018   4.6078978   5.4481254   .09779026   .17255214          -9
              r13        1967   5.6148957   5.4934587   3.8731968   4.7227936   5.5630212   .05187454   .12143698          -8
              r14        1968   5.8521849   5.7184482   4.0981865    4.959012   5.7992396    .0529453   .13373677          -7
              r15        1969   6.0814054   5.9484491   4.3281875   5.1958723   6.0360999   .04530551   .13295628          -6
              r16        1970   6.1700942   6.1276121   4.5073504   5.3315477   6.1717753   -.0016811   .04248213          -5
              r17        1971   6.2836334    6.301353   4.6810913   5.4756856   6.3159132   -.0322798  -.01771957          -4
              r18        1972   6.5555554   6.5871239   4.9668622   5.7701726   6.6104002   -.0548448  -.03156847          -3
              r19        1973   6.8107686   6.8682847    5.248023   6.0607328   6.9009604  -.09019189  -.05751614          -2
              r20        1974   7.1051843   6.9723439   5.3520823   6.2148671   7.0550947   .05008958   .13284038          -1
              r21        1975   7.3778917   7.0699992   5.4497375   6.3629322   7.2031598   .17473188   .30789247           0
              r22        1976   7.2329336   7.1482315   5.5279698   6.4359822   7.2762098  -.04327621   .08470212           1
              r23        1977   7.0898314   7.2243166   5.6040549   6.5046773   7.3449049  -.25507352  -.13448523           2
              r24        1978   6.7867036   7.2278781   5.6076164   6.4721866   7.3124142  -.52571058  -.44117448           3
              r25        1979   6.6398174   7.2275348   5.6072731   6.4818983   7.3221259  -.68230855  -.58771741           4
              r26        1980   6.5628392   7.2634039   5.6431422   6.5267782   7.3670058  -.80416667  -.70056474           5
              r27        1981   6.5007855   7.3222532   5.7019916   6.5966864    7.436914   -.9361285  -.82146776           6
              r28        1982   6.5450586   7.4001551   5.7798934   6.7104044    7.550632  -1.0055734  -.85509646           7
              r29        1983   6.5953298   7.4833274   5.8630657     6.82937   7.6695976  -1.0742679  -.88799757           8
              r30        1984   6.7614968   7.6141028   5.9938412   6.9285917   7.7688193  -1.0073225  -.85260612           9
              r31        1985   6.9371607   7.7514296   6.1311679   7.0327406   7.8729682  -.93580753  -.81426889          10
              r32        1986   7.3321912   8.1251221   6.5048599   7.5021062   8.3423338  -1.0101427   -.7929309          11
              r33        1987   7.7427881   8.5018091    6.881547   7.9712939   8.8115215  -1.0687335  -.75902098          12
              r34        1988   8.1205366   8.8598003   7.2395387   8.4300909    9.270319  -1.1497823  -.73926371          13
              r35        1989   8.5097112   9.2177296   7.5974679   8.8842478   9.7244759  -1.2147647  -.70801842          14
              r36        1990   8.7767779   9.4037838   7.7835217   9.1216793   9.9619074  -1.1851295  -.62700593          15
              r37        1991   9.0252787   9.5896816   7.9694195   9.3594685   10.199697  -1.1744179  -.56440294          16
              r38        1992   8.8738928   9.4494133   7.8291512   9.1523848   9.9926128  -1.1187201  -.57552046          17
              r39        1993   8.7182235   9.3104668   7.6902046   8.9410172   9.7812452  -1.0630217  -.59224325          18
              r40        1994   9.0181378   9.5237179   7.9034562   9.2902031   10.130431  -1.1122934  -.50558001          19
              r41        1995   9.4408739    9.731329   8.1110668   9.5933304   10.433558   -.9926846   -.2904551          20
              r42        1996   9.6865181   9.9606743   8.3404121   9.8364754   10.676703  -.99018532  -.27415615          21
              r43        1997   10.170666   10.298224   8.6779623   10.282063   11.122291  -.95162475  -.12755857          22
              you can do something like

              Code:
              mkf newframe
              cwf newframe
              svmat e(series), names(col)
              to save this matrix to a dataset, where you may further fine tune the observed versus predicted plot, if you wish (here, te5 is the pointwise treatment effect from the Forward DID model. You can also plot the dynamic effects, as estimated by sdid_event using 500 placebos.

              Code:
              mkf newframe2
              cwf newframe2
              svmat e(dyneff), names(col)
              returns the te5 variable above, however it comes with dynamic effects of the 95% CI

              Code:
              e(dyneff)[43,6]
                          eff          se           t          lb          ub   eventtime
               r1   .09525491   .06457192   1.4751753  -.03130607   .22181587         -20
               r2    .0376283   .06975174   .53946036  -.09908511   .17434171         -19
               r3  -.02178299   .07875734  -.27658361  -.17614737    .1325814         -18
               r4  -.07416093   .07331271  -1.0115699  -.21785384   .06953198         -17
               r5  -.12586021   .07001656   -1.797578  -.26309267   .01137224         -16
               r6  -.11593484   .02234003  -5.1895556  -.15972131  -.07214838         -15
               r7  -.10333084   .02524786   -4.092658  -.15281664  -.05384505         -14
               r8  -.03988528   .02651345   -1.504341  -.09185164   .01208109         -13
               r9   .00902916   .02168688   .41634178  -.03347714   .05153545         -12
              r10   .07958067   .02616021   3.0420506   .02830667   .13085468         -11
              r11    .1404568    .0263074   5.3390603   .08889429   .19201931         -10
              r12   .09779001   .01427055   6.8525724   .06981972    .1257603          -9
              r13   .05187453   .00050305   103.11983   .05088855   .05286051          -8
              r14   .05294526   .00667765   7.9287271   .03985707   .06603345          -7
              r15   .04530538   .01020914   4.4377265   .02529546    .0653153          -6
              r16  -.00168168   .02309938  -.07280193  -.04695647   .04359311          -5
              r17  -.03228008   .03684312  -.87614954  -.10449259   .03993243          -4
              r18  -.05484521   .05079281   -1.079783  -.15439911   .04470869          -3
              r19  -.09019195   .05767951   -1.563674  -.20324379   .02285989          -2
              r20   .05008901   .05376539   .93162179  -.05529116   .15546918          -1
              r21   .17473161   .04508366   3.8757195   .08636764   .26309559           0
              r22  -.04327666    .0064775  -6.6810722  -.05597256  -.03058076           1
              r23  -.25507367    .0568615  -4.4858766  -.36652219  -.14362513           2
              r24  -.52571046   .13196634  -3.9836709  -.78436446  -.26705644           3
              r25  -.68230855   .14685795  -4.6460443  -.97015011  -.39446697           4
              r26  -.80416667    .1279345  -6.2857685  -1.0549183  -.55341506           5
              r27  -.93612874   .10032932  -9.3305607  -1.1327742   -.7394833           6
              r28  -1.0055734   .10753969  -9.3507185  -1.2163512  -.79479557           7
              r29  -1.0742682   .11436744  -9.3931303  -1.2984284  -.85010803           8
              r30  -1.0073231   .12493283  -8.0629177  -1.2521914  -.76245481           9
              r31  -.93580782   .14014812  -6.6772771  -1.2104981  -.66111749          10
              r32  -1.0101432   .10854018  -9.3066292  -1.2228819  -.79740441          11
              r33  -1.0687333    .0779628  -13.708247  -1.2215405  -.91592622          12
              r34  -1.1497821   .06589618  -17.448387  -1.2789385  -1.0206256          13
              r35  -1.2147638   .05412474  -22.443781  -1.3208482  -1.1086793          14
              r36  -1.1851293    .0361721  -32.763626  -1.2560266  -1.1142319          15
              r37  -1.1744176   .01321682  -88.857834  -1.2003225  -1.1485126          16
              r38  -1.1187197   .01792586  -62.408131  -1.1538544   -1.083585          17
              r39  -1.0630208   .01910303  -55.646713  -1.1004628  -1.0255789          18
              r40  -1.1122924   .00738414  -150.63254  -1.1267654  -1.0978194          19
              r41  -.99268401   .03239937   -30.63899  -1.0561868  -.92918122          20
              r42   -.9901849   .02680755  -36.936794  -1.0427277   -.9376421          21
              r43  -.95162451   .04623134  -20.583967   -1.042238  -.86101109          22

              Comment


              • #22
                Show me the result of

                Code:
                which sdid_event

                Comment


                • #23
                  Code:
                  
                  . which sdid_event
                  command sdid_event not found as either built-in or ado-file
                  r(111);

                  Comment


                  • #24
                    Okay, so Stata is telling you sdid_event isn't on your system. What happens when you do

                    Code:
                    net install sdid_event, from("https://raw.githubusercontent.com/DiegoCiccia/sdid/main/sdid_event") replace

                    Comment


                    • #25
                      Works perfectly! Thanks

                      Comment


                      • #26
                        Hi again,

                        I have one more question, please. What does that mean?
                        Code:
                        .         fdid HEV, tr(treated) unitnames(idprovdis) gr1opts(title(FDID Results))
                        The data must be strongly balanced
                        r(498);
                        It seems to me that I have a balanced panel data, and I do not understand what's going on here...

                        Thank you again for your help and time!

                        Comment


                        • #27
                          You need the same number of periods for all units. This is also true for scm. Under the hood, fdid does

                          Code:
                          cap qui xtset
                          
                          cap as r(balanced)=="strongly balanced"
                          Before any estimation is conducted. For example,

                          Code:
                          clear *
                          u "https://github.com/jgreathouse9/FDIDTutorial/raw/main/basque.dta", clear
                          cls
                          
                          qui xtset
                          
                          return list
                          returns

                          Code:
                          scalars:
                                       r(tdelta) =  1
                                         r(tmax) =  1997
                                         r(tmin) =  1955
                                         r(gaps) =  0
                                         r(imax) =  17
                                         r(imin) =  1
                          
                          macros:
                                     r(panelvar) : "id"
                                      r(timevar) : "year"
                                         r(unit) : "yearly"
                                        r(unit1) : "y"
                                        r(tsfmt) : "%ty"
                                      r(tdeltas) : "1 year"
                                        r(tmaxs) : "1997"
                                        r(tmins) : "1955"
                                     r(balanced) : "strongly balanced"
                          We can see that the last macro indicates that the data are strongly balanced. When we do

                          Code:
                          clear *
                          u "https://github.com/jgreathouse9/FDIDTutorial/raw/main/basque.dta", clear
                          cls
                          
                          drop if id==4 & year == 1990
                          
                          qui xtset
                          
                          return list
                          
                          fdid gdp, tr(treat)
                          the code will fail because not all units have 43 observations.

                          Comment


                          • #28
                            Thank you so much! What is your advice on that, please? Should I drop those units that are not observed throughout the entire time period?

                            Comment


                            • #29
                              Yep, that's what you'll have to do. By the way, this would have been a problem for SCM too. SCM doesn't work with missing data or unbalanced panels, unless you're going to impute it with (Robust) PCA or something similar. It's really more of a data collection issue though- when you were getting your dataset together, could you see that not all provinces had the same number of observations? And if so, the question would be "well, why not?"

                              Comment


                              • #30
                                Ok nice! Thank you so much for your advices!

                                Comment

                                Working...
                                X