Announcement

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

  • How the graph the (parallel) trend in difference-in-differences

    Dear all,

    I am currently working on a DiD comparing Dutch firms to firms in a group of ontrol countries. The objective is to find out whether a law change in NL in 2008 has an effect ('year' runs from 2005 -2012).

    I ran several xtreg regressions. An example would be:

    Code:
    xtreg ROAni TA N_empl i.year i.POST##i.NL, robust cluster(sector) fe i(ID_BvD)


    For this purpose, I would like to graph the (parallel) time trend. Other discussions on this forum indicate I should use:

    graph twoway connect

    but I am struggling with the code.


    Could anyone provide me with a suggestion?


    Thank you for your help!



    Below a snapshot of my dataset.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long ID_BvD str89 company_name int year double(RDexp ROAni Turnover N_empl TA) long(country sector) float(POST NL survivor)
    1440 "CCR LOGISTICS SYSTEMS AG"                           2005          0   5.27            32931    49            15959 2 15 0 0 1
    2093 "GASCOGNE"                                           2005          0 -5.312           605450  2760           494247 3 19 0 0 1
     639 "COMPUGROUP MEDICAL AG"                              2005          0 10.934           119731   786           140774 2 15 0 0 1
    1926 "LISI"                                               2005      10100  5.144           622630  5863           691484 3 10 0 0 1
    1678 "EUROPACORP S.A."                                    2005          0  2.494           148079    63           230972 3 11 0 0 1
     567 "E.ON SE"                                            2005      24000  5.852         53390000 79947        126562000 2  6 0 0 1
    2269 "KARDAN N.V."                                        2005          0  2.975 463449.184728858  6120 1499164.65273744 4 11 0 1 1
    1666 "SEQUANA"                                            2005      17000  6.957          4092000 14305          5002000 3 19 0 0 1
     445 "HYRICAN INFORMATIONSSYSTEME AG"                     2005          0  6.689            63459    76            30736 2 18 0 0 1
     487 "CLAAS KGAA MBH"                                     2005      71526  3.355          2193738  8134          1611703 2  9 0 0 1
     335 "TUI AG"                                             2005          0  2.979         18514700 62947         15328400 2 11 0 0 1
    2232 "EUROPEAN ASSETS TRUST NV"                           2005          0 27.156              158     .           206295 4  1 0 1 0
    1356 "EVI AUDIO GMBH"                                     2005 3080.26226      0      74073.43437   477      33062.35534 2  9 0 0 0
     568 "TIPTEL AG"                                          2005          0 -2.944            31733   257            17223 2  9 0 0 0
    2046 "UNIBAIL-RODAMCO"                                    2005       1300 15.965           515700   953          8677200 3 11 0 0 1
    1516 "SPIR COMMUNICATION SA"                              2005          0 11.778           568714  4100           420200 3 15 0 0 1
    1541 "VISIODENT SA"                                       2005          0  7.282             9169    70             5122 3 11 0 0 1
    1795 "THEOLIA S.A."                                       2005          0   .074            14245    55            75924 3  6 0 0 1
    1833 "SAM"                                                2005          0  3.693            33080   223            33878 3 10 0 0 1
    1620 "EUROGERM S.A."                                      2005          0 14.233            35599   134            20481 3  5 0 0 1
      76 "REALCO"                                             2005          0  9.644             5333    31             3007 1 11 0 0 0
    1459 "EINHELL GERMANY AG"                                 2005          0  5.626           392473   926           207397 2  9 0 0 1
     773 "FRAPORT AG"                                         2005          0  4.079          2108800 25781          3951600 2 17 0 0 1
    1952 "VM MATERIAUX SA"                                    2005          0  6.068           459464  2000           243974 3  2 0 0 1
     934 "SOLAR-FABRIK AG"                                    2005          0   .776            51311   165            43833 2  9 0 0 1
      36 "PICANOL NV"                                         2005          0 -1.656           398384  2331           284706 1  9 0 0 1
    2102 "SABETON SA"                                         2005          0  -3.15            20070   178            85535 3  5 0 0 1
     156 "PROGEO HOLDING AG"                                  2005          0   .457             1689    17             6130 2  9 0 0 1
    2204 "EXACT HOLDING NV"                                   2005          0 11.601           224528  2698           276123 4 15 0 1 1
    2171 "HYDRATEC INDUSTRIES N.V."                           2005          0  9.886            32979   287            18390 4  2 0 1 1
     210 "DEINBOCK IMMOBILIEN-VERMOGENSVERWALTUNG AG"         2005          0      0             2110     .            22099 2 11 0 0 0
    1507 "SOCIETE INTERNATIONALE DE PLANTATIONS D' HEVEAS SA" 2005          0 14.441            95497  5506           108903 3 13 0 0 1
     943 "HEIDELBERGCEMENT AG"                                2005      43000  3.473          7958646 41260         11934651 2  2 0 0 1
    1884 "GROUPE VIAL"                                        2005          0 12.144            63080   178            45461 3 19 0 0 1
    1339 "ZF FRIEDRICHSHAFEN AG"                              2005     550000  3.416         11014000 53940          7230000 2  9 0 0 1
     493 "AHLERS AG"                                          2005          0  4.311           244447  3827           212280 2 16 0 0 1
     649 "OVB HOLDING AG"                                     2005          0 15.288           157610     .           100692 2 11 0 0 1
    1542 "CEGID GROUP"                                        2005          0  2.934           225878  2067           334935 3 11 0 0 1
    1515 "PIERRE ET VACANCES SA"                              2005          0  3.173          1239813  8637          1328780 3  7 0 0 1
    2166 "MECO INTERNATIONAL B.V."                            2005       3390   .419            40720   147            39610 4 11 0 1 0
     329 "ITRON ZAEHLER & SYSTEMTECHNIK GMBH"                 2005     90.647      .        30397.281     .        32739.288 2  9 0 0 1
    end


  • #2
    I would do this:
    Code:
    xtreg ROAni TA N_empl i.year##i.NL, robust cluster(sector) fe i(ID_BvD)
    margins year#NL
    marginsplot, xdimension(year)
    for results that are adjusted for the distributions of TA and N_empl.

    If you want crude trends, then you don't need a regression and can just do
    Code:
    separate ROAni, by(NL)
    collapse(mean) ROAmi?, by(NL year)
    graph twoway line ROAni? year, sort
    Note: Not tested because the example data contains only one year, so it does not support testing this kind of problem.
    Beware of typos or other error.

    Comment


    • #3
      Dear Clyde,


      Thank you for the suggestion to use the margins command. By adding 'noestimcheck' in predicting the margins I was able to generate the graphs.


      However, relating to the crude trends, I fail to fully comprehend your instructions.


      Could you please indicate what you mean with typos/ ROAmi / ROAni ?


      Below I provide a data sample including several years.

      Thank you!

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long ID_BvD str89 company_name int year double(RDexp ROAni Turnover N_empl TA) long country float(NL SME) double(ROAni0 ROAni1)
      1578 "CYBERGUN"                                   2012           0 -19.048        72482  155        67273 3 0 0 -19.048 .
       473 "ENVIO AG"                                   2010           0       .          515    .         4432 2 0 0       . .
       457 "GOINGPUBLIC MEDIA AG"                       2005           0       .         1539   10          525 2 0 1       . .
       145 "PIXELPARK AG"                               2009           0  -14.37        34980  377        22972 2 0 0  -14.37 .
       925 "MAGNA INTERNATIONAL (GERMANY) GMBH"         2006 20942.08826  -9.744 217568.27692 1271 301322.37397 2 0 0  -9.744 .
       145 "PIXELPARK AG"                               2008           0       .        44699  456        30277 2 0 0       . .
       621 "IPSEN INTERNATIONAL HOLDING GMBH"           2008        1530  -3.707       142115    .       227823 2 0 0  -3.707 .
      1313 "HUMANOPTICS AG"                             2006           0       .         6745   65         7979 2 0 1       . .
       174 "WALLSTREET: ONLINE AG"                      2010           0       .         2351   13         2597 2 0 1       . .
      1465 "S&O AGRAR AG"                               2007           0       .           23    .          523 2 0 0       . .
       300 "AFKEM AG"                                   2006           0       .        13332    5         2126 2 0 1       . .
       925 "MAGNA INTERNATIONAL (GERMANY) GMBH"         2008 29630.79039  -3.842 300063.81472 1366 276905.51457 2 0 0  -3.842 .
      1528 "LEXIBOOK LINGUISTIC ELECTRONIC SYSTEM SA"   2009           0  -11.31        39774  106        33500 3 0 1  -11.31 .
       300 "AFKEM AG"                                   2007           0       .        11375    3         1292 2 0 1       . .
      1933 "FONCIERE PARIS NORD"                        2011           0 -43.929         2449    6        20574 3 0 1 -43.929 .
      1422 "DATAPHARM NETSYSTEMS AG"                    2006           0       .         2662   27          939 2 0 1       . .
       523 "SOLARHYBRID AG"                             2010           0 -30.531       113523   70        27068 2 0 1 -30.531 .
      1315 "AREVA GMBH"                                 2009 48070.57835  -9.605 973403.78119 4387  898514.1628 2 0 0  -9.605 .
      1841 "AB SCIENCE SA"                              2009        5833 -57.575          316   71        14086 3 0 1 -57.575 .
       291 "CONERGY AG"                                 2011         700 -47.401       770300 1461       342400 2 0 0 -47.401 .
      1731 "CIBOX INTER@CTIVE"                          2008           0       .        21586    7         3267 3 0 1       . .
      1050 "TETEC TISSUE ENGINEERING TECHNOLOGIES AG"   2012    3370.262 -65.764     5728.345   43     2236.042 2 0 1 -65.764 .
       703 "CONVISUAL AG"                               2008           0       .        14497   34         4621 2 0 1       . .
       803 "AETERNA ZENTARIS GMBH"                      2012 17240.61324 -94.909  25985.61362   80  22960.87459 2 0 1 -94.909 .
       310 "INTELIS AG"                                 2007           0 -32.668        17485  134        11874 2 0 1 -32.668 .
      1558 "AUPLATA SA"                                 2008           0 -84.951         6605    .        14300 3 0 0 -84.951 .
       913 "MEDICAL COLUMBUS AKTIENGESELLSCHAFT"        2008           0       .         1542    .         1498 2 0 0       . .
      1250 "LENA BETEILIGUNGS AG"                       2008           0       .         3545    .          520 2 0 0       . .
      1000 "ELEXXION AG"                                2009           0  -69.98         2375   17         3048 2 0 1  -69.98 .
      1539 "GECI INTERNATIONAL SA"                      2006           0 -17.384        38227  630        20737 3 0 0 -17.384 .
      1315 "AREVA GMBH"                                 2007  40985.0502 -10.349 828289.98855 3197 794141.48876 2 0 0 -10.349 .
      1751 "HOLOSFIND"                                  2010           0 -61.978         7225  108        11680 3 0 1 -61.978 .
      2011 "BLEECKER"                                   2009           0 -10.325        27255    .       418522 3 0 0 -10.325 .
       174 "WALLSTREET: ONLINE AG"                      2009           0       .         3231   27         3752 2 0 1       . .
      1869 "LOGIN PEOPLE"                               2011           0       .          302   11          758 3 0 1       . .
       582 "BEROA TECHNOLOGY GROUP GMBH"                2012     448.191 -18.477   276156.688 2206   156887.564 2 0 0 -18.477 .
      1802 "ADOMOS SA"                                  2011           0 -79.607         2142   38         7071 3 0 1 -79.607 .
      1313 "HUMANOPTICS AG"                             2008           0       .         9009   76         8250 2 0 1       . .
       852 "DRILLISCH AG"                               2008           0       .       353093  345       182259 2 0 0       . .
      1313 "HUMANOPTICS AG"                             2009           0       .         7829   70         6955 2 0 1       . .
      1332 "SUMITOMO SHI DEMAG PLASTICS MACHINERY GMBH" 2009        5871 -41.413        86304  829        81814 2 0 0 -41.413 .
      1860 "NANOBIOTIX"                                 2011        3104       .         1360   31         2913 3 0 1       . .
       769 "RALOS NEW ENERGIES AG"                      2006           0       .         2844   36         1191 2 0 1       . .
       104 "ABO-GROUP"                                  2010           0 -50.926        46052    .        59443 1 0 0 -50.926 .
       703 "CONVISUAL AG"                               2006           0       .        11616   29         4754 2 0 1       . .
      1368 "SITECO BELEUCHTUNGSTECHNIK GMBH"            2012       11745  -9.997       181770 1068       237263 2 0 0  -9.997 .
      1217 "118000 AG"                                  2006        2594       .         2878   95        12556 2 0 1       . .
       803 "AETERNA ZENTARIS GMBH"                      2010 14509.00493 -80.329  20162.24954   87  21701.09435 2 0 1 -80.329 .
       304 "HCI CAPITAL AG"                             2012           0       .        41528  208        65665 2 0 1       . .
       320 "ROPAL EUROPE AG"                            2011           0 -46.019          257    6         3605 2 0 1 -46.019 .
       703 "CONVISUAL AG"                               2010           0       .        19101   35         5381 2 0 1       . .
      1313 "HUMANOPTICS AG"                             2007           0       .         6939   71         9141 2 0 1       . .
      1664 "MILLIMAGES"                                 2008           0 -22.467        32482   52        93899 3 0 1 -22.467 .
       300 "AFKEM AG"                                   2009           0       .          169    .          825 2 0 0       . .
      1201 "ISARIA WOHNBAU AG"                          2011           0  -5.301       159297   33       218489 2 0 0  -5.301 .
       564 "MARBERT HOLDING AG"                         2008           0 -33.326        15724   72         9215 2 0 1 -33.326 .
       202 "MYHAMMER HOLDING AG"                        2011           0 -54.256        14685   55         4276 2 0 1 -54.256 .
      1201 "ISARIA WOHNBAU AG"                          2010           0 -31.998        77837   47       235658 2 0 0 -31.998 .
       703 "CONVISUAL AG"                               2009           0       .        16933   32         4972 2 0 1       . .
       913 "MEDICAL COLUMBUS AKTIENGESELLSCHAFT"        2007           0       .         1447    .         1891 2 0 0       . .
      end

      Comment


      • #4
        Could you please indicate what you mean with typos/ ROAmi / ROAni ?
        Since your original data set contained only one year of data, I was unable to really test my code with your example. So I gave you untested code. I am aware that I make fairly frequent typographical errors, so I was warning you that there might be some. In fact, it turns out, there were. ROAmi was a typo for ROAni.

        The correct code, tested with your example, is:

        Code:
        collapse (mean) ROAni, by(NL year)
        separate ROAni, by(NL)
        graph twoway line ROAni? year, sort
        Notes:
        1. It doesn't really matter whether you do the -collapse- before -separate- or the other way around, but if you -separate- first then the -collapse- command has to specify ROAni? instead of ROAni so that it operates on ROAni1 and ROAni2.

        2. If you are not familiar with the -separate- command, which is not used very much but is quite helpful in exactly this situation, read -help separate-. What you will see is that it takes ROAni and creates separate variables, one for each level of the variable NL. Since NL has two levels, 0, and 1 (though in your example, only 0 is instantiated), you will get two variables, ROAni1 and ROAni2. The first contains the values of ROAni in those observations where NL == 0 and has missing values elsewhere. The second analogously presents the values of ROAni where NL == 1. Th syntax -ROAni?- in the -graph twoway- command represents the use of wildcards to represent a group of variables. The ? wildcard is a placeholder for any single character. So, ROAni? expands to ROAni1 ROAni2. (If you had 20 such variables, it would stand for ROAni1 through ROAni9, but would not cover ROAni10 because 10 is not a single character.) So the -graph twoway- command will plot both ROAni1 and ROAni2 over time.

        Comment


        • #5
          Good afternoon Clyde,

          Thanks again for your very useful response!



          Can I please ask for your opinion on a more general issue regarding my work?

          As I mentioned in an earlier post, I am studying the effect of innovation on firm performance, using a DiD method. In 2008 there was a law change in NL. The 'treated' country therefore is NL and I have 3 control countries. My sample includes 8 years of data, where the treatment cut-off point lies in the middle.

          So far, I have been doing regression using the fixed effects estimator, e.g.

          Code:
           xtreg ROA TA N_empl i.POST##i.NL, robust cluster( sector ) fe i(ID_BvD)
          As a result the coefficient on 'NL' base level is of course omitted.


          I am using FE because I worry about unobserved heterogeneity / omitted variable bias.

          However, at this point I think running a standard classical DiD with a 'treatment' dummy, a 'post' dummy and a 'treatment' - 'post' interaction should already account for unobserved heterogeneity. Therefore I do not see the logic of performing the DiD using a FE estimator.

          What I think would be best is to run the DiD with OLS using the pre- and post dummies + controls and to add a separate regression with year*NL interaction effects, which I estimate using FE.




          Your contribution would be well appreciated!

          Best regards,

          Joost

          Comment


          • #6
            But there would still be unobserved heterogeneity at the ID_BvD level not accounted for by that approach. Moreover, the effect you are trying to estimate between the NL and the other countries is best manifested by changes within ID_BvDs over time, and the fixed effects estimator gives the best estimate of those within-unit changes.

            Comment


            • #7
              Hi there, I am working on a triple difference analysis and would also like to graph the parallel trends assumption. Am I able to do this with the stata code suggested here, using margins & marginsplot?

              Thank you,

              Ash

              Comment


              • #8
                Hi Ash, this thread is completed and the code works. Please open a new threat for other questions.

                Comment

                Working...
                X