Announcement

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

  • DiD on Panel data with fixed effect

    Dear Statalist,

    I want to run DiD model, based on (Bas & Strauss-Kahn, 2015)
    Click image for larger version

Name:	export.JPG
Views:	3
Size:	13.7 KB
ID:	1664814


    Ordinary will code 0 for control group dan 1 for treatment group. T is tariff variabel and will be different over years (2000, 2001, 2002, 2003, 2004, 2005, 2006). Sizei,t0*αt corresponds to initial firm size trends, where the initial size of firm i is defined by the number of imported varieties. αik, αct, αst and αpt are firm-product, destination country-year, HS4-year and province-year fixed effects and ηipkct an i.i.d. component.

    My questions :
    1. How to run this model in Stata (I confused because there is so much fixed effect variabel and the tariff variable is not pre and post treatment (like usual DiD model that code 0 for pre-treatment and 1 for post-treatment)

    I run xtreg P ordinary T ordinary*T size*at aik act ast apt, fe vce(robust)

    Is it true?

    2. How to chek parallel trend assumption

    Please, I will be very grateful if you could please explain the answer of my question.

    Thanks a lot!
    Attached Files
    Last edited by lilis husna; 16 May 2022, 04:50.

  • #2
    See this command.

    EDIT: And how many units are treated? How many are untreated?

    Comment


    • #3
      Concerning your question 2, I once had the same question and Jared Greathouse recommended that I read this paper: https://jonathandroth.github.io/asse...view_Paper.pdf

      Comment


      • #4
        thanks Jared Greathouse.

        so, I can run reghdfe P ordinary T ordinary*T size*at, absorb(aik, act, ast, apt)

        is it right?
        do i still need to apply xtset because of my panel data ?

        I have about 8000 observation for treated group dan 1000 observation for control group (total for 8 years)

        thanks Maxence Morlet

        Comment


        • #5
          If you have more than one unit across more than one period of time, then yes you should always xtset your data.

          Comment


          • #6
            Jared Greathouse , I tried twice.
            First, I use reghdfe
            Second, I use
            xtset
            reghdfe

            I got same output. So, i want to know, is reghdfe compatible with panel data?

            Comment


            • #7
              Yep

              Comment


              • #8
                Dear Jared Greathouse, I'm sorry, I still have a question. When I run reghdfe, does that mean I use canonical DiD?

                Comment


                • #9
                  Canonical DiD would be a 2x2 configuration (one pre treatment period, one posttreatment period, one control group and one treated)

                  Sergio Correia's (2017) reghdfe is a fixed effects regression with high dimensional fixed effects

                  See here: http://scorreia.com/software/reghdfe/

                  Comment


                  • #10
                    So, what syntax should I use? do you have any suggestion Maxence Morlet?

                    Comment


                    • #11
                      Let's clear something up for a moment. I think it'll be helpful to distinguish between an estimator and a design. Strictly speaking, you can have a negative binomial regression based difference-in-differences design. Or a synthetic control design that uses poisson regression.

                      One is an estimator (poisson, beta-regression), and another is the way you're structuring your study to begin with.

                      I'm not familiar with reghdfe, and you'll need to read the help file so you can get it to do what you want. Without a data example however, most of what we say is meaningless.

                      So please, post your data via dataex.

                      Comment


                      • #12
                        I'm sorry, I am a beginner, here. how to post dataex, Jared Greathouse?

                        Comment


                        • #13
                          Like this

                          Comment


                          • #14
                            This is my DiD model,
                            Click image for larger version

Name:	ekspor.JPG
Views:	1
Size:	11.4 KB
ID:	1666854


                            This is my dataex

                            Code:
                            * Example generated by -dataex-. To install: ssc install dataex
                            clear
                            input str26 id str4 year str15 firm str2 country str8 hs double pxikc byte ftai double tarifi int sizei_t0
                            "010005742055000 87089999TH" "2017" "010005742055000" "TH" "87089999" .01 1 2.0209   7
                            "010000990092000 87082993BE" "2018" "010000990092000" "BE" "87082993" .01 1  .2301  45
                            "013044060062000 84099945AU" "2017" "013044060062000" "AU" "84099945" .03 0  8.082   2
                            "010005742055000 87089991TH" "2018" "010005742055000" "TH" "87089991" .04 1 4.9531   7
                            "315998443433000 87089999JP" "2019" "315998443433000" "JP" "87089999" .04 1  .2262   6
                            "311906416431000 85129020TH" "2016" "311906416431000" "TH" "85129020" .06 1 2.6549   8
                            "030885529063000 86090090IQ" "2018" "030885529063000" "IQ" "86090090" .06 0     10   1
                            "861884450412000 87059090CN" "2019" "861884450412000" "CN" "87059090" .06 1 5.0441   3
                            "317523454032000 87089999SG" "2017" "317523454032000" "SG" "87089999" .07 0 9.2653  34
                            "016627986062000 85115099CN" "2017" "016627986062000" "CN" "85115099" .07 0     10  19
                            "317523454032000 84099949SG" "2017" "317523454032000" "SG" "84099949" .08 0 9.2653  34
                            "018246660058000 86090010FR" "2017" "018246660058000" "FR" "86090010" .09 0      5   1
                            "746572965004000 87089220TW" "2019" "746572965004000" "TW" "87089220" .09 1      0   1
                            "025199266055000 94012010IN" "2019" "025199266055000" "IN" "94012010" .09 0     10   2
                            "010710424059000 84099117SG" "2019" "010710424059000" "SG" "84099117" .09 0 9.8378   1
                            "013085246091000 85114099DE" "2019" "013085246091000" "DE" "85114099"  .1 0 9.9041  43
                            "010710424059000 84099114SG" "2019" "010710424059000" "SG" "84099114"  .1 0 9.8378   1
                            "010000990092000 87089252MY" "2019" "010000990092000" "MY" "87089252"  .1 1   .268  45
                            "010000990092000 87089930TH" "2017" "010000990092000" "TH" "87089930" .11 1  1.251  45
                            "013085246091000 87089991DE" "2019" "013085246091000" "DE" "87089991" .11 0 9.9041  43
                            "010017200057000 94012090KR" "2016" "010017200057000" "KR" "94012090" .13 0     10   2
                            "704710607721000 87085099BE" "2019" "704710607721000" "BE" "87085099" .13 0 8.6917  24
                            "010712511055000 87082920TW" "2016" "010712511055000" "TW" "87082920" .14 1  5.588   6
                            "013044060062000 87089220SG" "2019" "013044060062000" "SG" "87089220" .15 0     10   2
                            "010710424059000 84099118SG" "2019" "010710424059000" "SG" "84099118" .15 0 9.8378   1
                            "013859574091000 87089921JP" "2019" "013859574091000" "JP" "87089921" .16 1 8.5998  39
                            "210384939431000 87089199TH" "2016" "210384939431000" "TH" "87089199" .17 1 7.6154   2
                            "815322086001000 87089970TL" "2018" "815322086001000" "TL" "87089970" .17 0  9.023   3
                            "314635459413000 87089962JP" "2018" "314635459413000" "JP" "87089962" .17 1 9.7073   1
                            "010000990092000 87082915BE" "2018" "010000990092000" "BE" "87082915" .17 1  .2301  45
                            "715808606027000 87082999AE" "2016" "715808606027000" "AE" "87082999" .18 0 5.8587   4
                            "719492407003000 87081090TH" "2018" "719492407003000" "TH" "87081090" .18 0 5.1735   2
                            "313765547413000 87083090JP" "2018" "313765547413000" "JP" "87083090" .18 1  .1561   7
                            "010032605091000 87088019AU" "2017" "010032605091000" "AU" "87088019" .19 0 9.9486   8
                            "838778280005000 87081090TZ" "2019" "838778280005000" "TZ" "87081090" .19 1 6.8511   4
                            "018695080062000 94012010MY" "2017" "018695080062000" "MY" "94012010"  .2 0 11.003  18
                            "723317277002000 87089925PK" "2017" "723317277002000" "PK" "87089925" .21 1   .797   2
                            "312716210431000 87082993KR" "2015" "312716210431000" "KR" "87082993" .22 1 6.3186   4
                            "723317277002000 87089999PK" "2017" "723317277002000" "PK" "87089999" .22 1   .797   2
                            "010000990092000 87089962ZA" "2018" "010000990092000" "ZA" "87089962" .24 1  .2301  45
                            "021160221056000 87081090JP" "2019" "021160221056000" "JP" "87081090" .24 1 1.0128  21
                            "021160221056000 87085019JP" "2016" "021160221056000" "JP" "87085019" .25 1 8.8252  21
                            "016627986062000 87083021SG" "2016" "016627986062000" "SG" "87083021" .25 0 9.0945  19
                            "012093605721000 87089924IE" "2016" "012093605721000" "IE" "87089924" .25 0 9.8213   4
                            "861680270435000 87085026AE" "2019" "861680270435000" "AE" "87085026" .25 0      5   2
                            "010710424059000 85114099SG" "2019" "010710424059000" "SG" "85114099" .25 0 9.8378   1
                            "013107743123001 87083029SG" "2016" "013107743123001" "SG" "87083029" .26 0     10   1
                            "838778280005000 87081090AE" "2019" "838778280005000" "AE" "87081090" .26 1 6.8511   4
                            "032719734031000 86090010TW" "2018" "032719734031000" "TW" "86090010" .27 0     10   1
                            "013006572092000 87084099JP" "2017" "013006572092000" "JP" "87084099" .28 1 3.2908  75
                            "013006572092000 84099942JP" "2017" "013006572092000" "JP" "84099942" .28 1 3.2908  75
                            "021160221056000 87083090JP" "2018" "021160221056000" "JP" "87083090" .28 1 1.9123  21
                            "010000990092000 87089194VN" "2018" "010000990092000" "VN" "87089194" .28 1  .2301  45
                            "838916211447000 87081090AE" "2019" "838916211447000" "AE" "87081090" .28 1      5   2
                            "020588513058000 86090010SG" "2018" "020588513058000" "SG" "86090010" .29 0      5   1
                            "013006572092000 87085096JP" "2016" "013006572092000" "JP" "87085096"  .3 1 4.7278  75
                            "018695080062000 87089940MY" "2017" "018695080062000" "MY" "87089940" .31 0 11.003  18
                            "311906416431000 85129020VN" "2018" "311906416431000" "VN" "85129020" .31 1 1.3327   8
                            "010005742055000 87089220CN" "2019" "010005742055000" "CN" "87089220" .31 1 5.5092   7
                            "018246660058000 86090010MY" "2017" "018246660058000" "MY" "86090010" .32 0      5   1
                            "015397102038000 85115029SG" "2017" "015397102038000" "SG" "85115029" .33 0     10   2
                            "010005148092000 87089999JP" "2015" "010005148092000" "JP" "87089999" .34 1  6.763  20
                            "018695080062000 87089921MY" "2017" "018695080062000" "MY" "87089921" .34 0 11.003  18
                            "018695080062000 84099149MY" "2017" "018695080062000" "MY" "84099149" .34 0 11.003  18
                            "013044060062000 87087016CN" "2019" "013044060062000" "CN" "87087016" .34 0     10   2
                            "010000990092000 87085094IN" "2016" "010000990092000" "IN" "87085094" .36 1 3.7708  45
                            "010695369091000 84099949AU" "2019" "010695369091000" "AU" "84099949" .36 0 9.7226 124
                            "312716210431000 87088092IN" "2015" "312716210431000" "IN" "87088092" .37 1 6.3186   4
                            "013044060062000 87089210JP" "2019" "013044060062000" "JP" "87089210" .37 0     10   2
                            "715808606027000 87082999JO" "2016" "715808606027000" "JO" "87082999" .38 0 5.8587   4
                            "017131319091000 87083029KR" "2017" "017131319091000" "KR" "87083029" .38 1 8.1423   8
                            "021160221056000 84082096JP" "2018" "021160221056000" "JP" "84082096" .38 1 1.9123  21
                            "016043812092000 87089999KR" "2015" "016043812092000" "KR" "87089999" .39 1  .2906   7
                            "018695080062000 87089930MY" "2017" "018695080062000" "MY" "87089930"  .4 0 11.003  18
                            "861680270435000 87087023AE" "2019" "861680270435000" "AE" "87087023"  .4 0      5   2
                            "838778280005000 87089411CN" "2019" "838778280005000" "CN" "87089411"  .4 1 6.8511   4
                            "013859574091000 84099115JP" "2019" "013859574091000" "JP" "84099115"  .4 1 8.5998  39
                            "018695080062000 87089499MY" "2017" "018695080062000" "MY" "87089499" .42 0 11.003  18
                            "314164021413000 87082993JP" "2018" "314164021413000" "JP" "87082993" .42 0     10   1
                            "715808606027000 87089199SG" "2016" "715808606027000" "SG" "87089199" .43 0 5.8587   4
                            "317889590071000 87082919JP" "2018" "317889590071000" "JP" "87082919" .43 0 9.8891   3
                            "015686363641000 87087019DE" "2018" "015686363641000" "DE" "87087019" .43 1 5.0666   2
                            "010710424059000 84099119SG" "2019" "010710424059000" "SG" "84099119" .45 0 9.8378   1
                            "013044060062000 87084099NL" "2017" "013044060062000" "NL" "87084099" .46 0  8.082   2
                            "013859574091000 84099117JP" "2018" "013859574091000" "JP" "84099117" .47 1 7.6642  39
                            "838778280005000 87084019IN" "2019" "838778280005000" "IN" "87084019" .47 1 6.8511   4
                            "010712511055000 87082920JP" "2016" "010712511055000" "JP" "87082920" .48 1  5.588   6
                            "733055834413000 87089925CN" "2018" "733055834413000" "CN" "87089925" .49 1 4.3487  41
                            "312716210431000 87082993IN" "2015" "312716210431000" "IN" "87082993"  .5 1 6.3186   4
                            "010000990092000 87083010TH" "2016" "010000990092000" "TH" "87083010"  .5 1 3.7708  45
                            "761494228004000 87088099FR" "2018" "761494228004000" "FR" "87088099" .51 1 8.8369   5
                            "013085246091000 87089999DE" "2019" "013085246091000" "DE" "87089999" .51 0 9.9041  43
                            "010000990092000 87089262VN" "2019" "010000990092000" "VN" "87089262" .51 1   .268  45
                            "010718294055000 84099145FI" "2017" "010718294055000" "FI" "84099145" .52 0     10   2
                            "012698056092000 86090010SG" "2018" "012698056092000" "SG" "86090010" .52 1 2.3132   3
                            "021126958951000 86090010MY" "2018" "021126958951000" "MY" "86090010" .53 0     10   5
                            "010000990092000 87089199SA" "2019" "010000990092000" "SA" "87089199" .53 1   .268  45
                            "313765547413000 87083090JP" "2017" "313765547413000" "JP" "87083090" .54 1 1.5135   7
                            "013627526073000 87089919SE" "2019" "013627526073000" "SE" "87089919" .54 0     10   5
                            "664589983125000 94012090TH" "2016" "664589983125000" "TH" "94012090" .55 0  9.607   4
                            end
                            and I use this code
                            Code:
                            egen ID=group(id)
                            egen CT=group(country year)
                            egen IK=group(firm hs)
                            egen at=group(year)
                            gen sizet=sizei_t0*at
                            gen A=ftai*tarifi
                            reghdfe pxikc tarifi ftai A sizet, absorb(CT IK)
                            is my code correct??

                            Comment


                            • #15
                              I would do
                              Code:
                              reghdfe pxikc sizei_t0##i.at ftai##tarifi, absorb(CT IK)
                              since this means you don't need to make interactions by hand.

                              Comment

                              Working...
                              X