Announcement

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

  • Graphical representation of pretreatment trends in Diff-in-Diff regression

    Dear Stata users,

    I have estimated a Diiference in Difference model with three waves of household income and expenditure survey data. My pretreatment years are 2000 and 2005. To check the parallel path assumption, I need to execute a graphical representation of the pre treatment trends. As I haven't done it before, can anyone let me know how to do this in Stata?

    Cheers,
    Azreen Karim.

  • #2
    It's not hard, but it depends on how your data is set up. Show us a sample of your data covering a few panels in each group and all the relevant years; use the -dataex- command to do that. (If you don't have -dataex-, run -ssc install dataex- and read -help dataex- for the simple instructions.)

    Comment


    • #3
      Variables Mean mean
      OUTCOME VARIABLES Treatment2005 Treatment2000 control2005 control2000
      Per capita total income 31078.89 31735.79 29615.76 23474.18
      Per capita crop income 7060.284 7197.541 6397.446 4153.973
      Thanks Clyde. I just attempted to show the mean (average) of the treatment and controls of the pretreatment years. Do you think its possible to draw a graph to check the parallel path assumption with this table? I have used the user written command DIFF to excute the DID model and my dataset is a repeated cross section one.

      Cheers,
      Azreen.

      Comment


      • #4
        OK, I did ask you to use -dataex- to show the example. What you posted is readable to my eye, but it's not -datatex- output and I don't want to fiddle around with it to get it into Stata. So I won't give you exact code but just point the general direction here.

        Step 1. Reshape Treatment and control to long layout with year as the -j()- variable.

        Step 2. Something like this:
        Code:
        graph twoway connect Treatment control year if outcome == "Per capita total income", name(total, replace)
        graph twoway connect Treatment control year if outcome == "Per capita crop income", name(crop, replace)
        You should read the manual on -graph twoway connect- to see the various options you can use to change the appearance of the graphs generated above and customize them to your taste.

        If you want more specific advice, or if this wasn't what you had in mind, post back. But do so with -dataex- output representing your data.

        Comment


        • #5
          Thanks Clyde. I will follow your instructions first and then get back to you. Thanks again.

          Cheers,
          Azreen.

          Comment


          • #6
            Hi Clyde,

            Here is the code in using dataex to graphically verify the parallel path assumption in Diff-in-Diff model:

            BEFORE SHOCK
            ----------------------- copy starting from the next line -----------------------
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str21 outcomevariables int year float(treatment control)
            "perrcapitatotalincome" 2000 31723.62 23473.42
            "perrcapitatotalincome" 2005 30994.19 29496.81
            "perrcapitatotalincome" 2010 917693.2 936485.5
            end
            ------------------ copy up to and including the previous line ------------------

            AFTER SHOCK

            ----------------------- copy starting from the next line -----------------------
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str20 outcomevariables int year float(treatment control)
            "percapitatotalincome" 2000 31078.89 23474.18
            "percapitatotalincome" 2005 31078.89 29615.76
            "percapitatotalincome" 2010 916873.1 26577.35
            end
            ------------------ copy up to and including the previous line ------------------

            Could you please let me know how the graphs should look like using Stata commands?

            Cheers,
            Azreen.

            Comment


            • #7
              Dear Stata users,

              Here is the code to graphically verify the parallel path assumption in Diff-in-Diff model:

              BEFORE SHOCK
              ----------------------- copy starting from the next line ----------------------- Code:

              * Example generated by -dataex-. To install: ssc install dataex clear input str21 outcomevariables int year float(treatment control) "perrcapitatotalincome" 2000 31723.62 23473.42 "perrcapitatotalincome" 2005 30994.19 29496.81 "perrcapitatotalincome" 2010 917693.2 936485.5 end
              ------------------ copy up to and including the previous line ------------------

              AFTER SHOCK

              ----------------------- copy starting from the next line ----------------------- Code:

              * Example generated by -dataex-. To install: ssc install dataex clear input str20 outcomevariables int year float(treatment control) "percapitatotalincome" 2000 31078.89 23474.18 "percapitatotalincome" 2005 31078.89 29615.76 "percapitatotalincome" 2010 916873.1 26577.35 end
              ------------------ copy up to and including the previous line ------------------

              Could anyone please let me know how to graph these trends using Stata commands?

              Cheers,
              Azreen.

              Comment


              • #8
                Azreen,
                Clyde gave you exactly all you need to create the graph you want in #4, reposting your data without [CODE] tags won't help you to get more help.
                Based on your post in #1 and Clyde's suggestions, I think this is what you are looking for.

                Code:
                clear
                input str21 outcomevariables int year float(treatment control)
                "perrcapitatotalincome" 2000 31723.62 23473.42
                "perrcapitatotalincome" 2005 30994.19 29496.81
                "perrcapitatotalincome" 2010 917693.2 936485.5
                end
                g byte shock=0
                tempfile to_append
                save `to_append'
                clear
                input str20 outcomevariables int year float(treatment control)
                "percapitatotalincome" 2000 31078.89 23474.18
                "percapitatotalincome" 2005 31078.89 29615.76
                "percapitatotalincome" 2010 916873.1 26577.35
                end
                g byte shock=1
                append using `to_append'
                
                tw connect treatment control year if year<2010 & shock==0, ///
                xlab(2000 2005) yt("Total income per capita") ///
                t("Pre Treatment Trends")

                Comment


                • #9
                  Thanks Oded. I will get back to you after following your instructions.

                  Cheers,
                  Azreen.

                  Comment


                  • #10
                    Originally posted by Clyde Schechter View Post
                    OK, I did ask you to use -dataex- to show the example. What you posted is readable to my eye, but it's not -datatex- output and I don't want to fiddle around with it to get it into Stata. So I won't give you exact code but just point the general direction here.

                    Step 1. Reshape Treatment and control to long layout with year as the -j()- variable.

                    Step 2. Something like this:
                    Code:
                    graph twoway connect Treatment control year if outcome == "Per capita total income", name(total, replace)
                    graph twoway connect Treatment control year if outcome == "Per capita crop income", name(crop, replace)
                    You should read the manual on -graph twoway connect- to see the various options you can use to change the appearance of the graphs generated above and customize them to your taste.

                    If you want more specific advice, or if this wasn't what you had in mind, post back. But do so with -dataex- output representing your data.

                    Dear Clyde,

                    I am trying to plot a parallel trend graph in stata to show the trend between treatment and control (treated 0/1) for the variables;usdincome usdcapital usdsavings employees.Please find the output from dataex for your review.I'm using stata 12.1.

                    ----------------------- copy starting from the next line -----------------------
                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input long hhid int year byte trained float(usdincome usdcapital usdsavings) byte employees
                    2016001 2016 1  243.6548    355.33  5.076142 2
                    2016001 2013 1 106.82768  278.6809 11.611704 0
                    2016002 2016 1 162.43655    355.33  91.37056 3
                    2016002 2013 1 116.11704  336.7394  46.44682 1
                    2016003 2013 1 104.50534 174.17557  46.44682 0
                    2016003 2016 1 223.35025 304.56854  81.21828 2
                    2016004 2016 1  203.0457 304.56854  71.06599 1
                    2016004 2013 1  92.89363  290.2926  46.44682 1
                    2016005 2013 1 120.76173  336.7394  46.44682 1
                    2016005 2016 1 213.19797  385.7868  81.21828 1
                    2016006 2013 1 127.72874 174.17557  46.44682 0
                    2016006 2016 1  182.7411  365.4822  81.21828 2
                    2016007 2013 1  99.86066  290.2926  46.44682 1
                    2016007 2016 1  243.6548  375.6345  91.37056 1
                    2016008 2013 1  99.86066  278.6809  46.44682 0
                    2016008 2016 1  182.7411    355.33  81.21828 2
                    2016009 2016 1   177.665 304.56854  71.06599 1
                    2016009 2013 1  125.4064  336.7394  23.22341 1
                    2016010 2016 1 263.95938 294.41623  81.21828 1
                    2016010 2013 1  148.6298  290.2926 11.611704 1
                    2016011 2016 1  243.6548 304.56854  91.37056 2
                    2016011 2013 1 120.76173  278.6809  46.44682 0
                    2016012 2016 1 233.50253  365.4822  71.06599 1
                    2016012 2013 1 139.34045  336.7394  46.44682 1
                    2016013 2016 1 213.19797  345.1777  71.06599 2
                    2016013 2013 1 116.11704 174.17557  46.44682 0
                    2016014 2013 1 139.34045  278.6809  46.44682 0
                    2016014 2016 1 223.35025    355.33  81.21828 2
                    2016015 2016 1  192.8934  324.8731         0 1
                    2016015 2013 1 120.76173  406.4096  92.89363 2
                    2016016 2016 1 263.95938  365.4822 15.228426 1
                    2016016 2013 1 116.11704  290.2926 15.095216 1
                    2016017 2013 1 139.34045  278.6809  5.805852 0
                    2016017 2016 1 304.56854    355.33  24.36548 2
                    2016018 2013 1 130.05109  336.7394  23.22341 1
                    2016018 2016 1  243.6548  385.7868 22.335026 1
                    2016019 2016 1  182.7411    355.33         0 2
                    2016019 2013 1 116.11704  336.7394  25.54575 1
                    2016020 2013 1 116.11704 174.17557  5.805852 0
                    2016020 2016 1 223.35025  385.7868  20.30457 2
                    2016021 2016 1  243.6548    355.33 15.228426 2
                    2016021 2013 1 111.47236  278.6809 15.095216 0
                    2016022 2013 1 139.34045  336.7394  5.805852 1
                    2016022 2016 1 213.19797  406.0914  24.36548 1
                    2016023 2013 1  92.89363 174.17557  23.22341 0
                    2016023 2016 1 263.95938  324.8731 22.335026 2
                    2016024 2016 1 284.26395  375.6345 17.258883 1
                    2016024 2013 1 150.95215  290.2926 17.417557 1
                    2016025 2013 1 139.34045  278.6809 16.256386 0
                    2016025 2016 1  324.8731    355.33  27.41117 2
                    2016026 2013 1 106.82768  336.7394  9.289363 1
                    2016026 2016 1  182.7411 304.56854  18.27411 1
                    2016027 2016 1 213.19797  385.7868 15.228426 2
                    2016027 2013 1 116.11704 174.17557  6.967022 0
                    2016028 2016 1 263.95938  406.0914  71.06599 1
                    2016028 2013 1 106.82768  290.2926  23.22341 1
                    2016029 2013 1 174.17557  278.6809 34.835114 0
                    2016029 2016 1 162.43655    355.33  50.76142 2
                    2016030 2016 1 213.19797  324.8731 10.152285 1
                    2016030 2013 1 130.05109  255.4575  5.805852 2
                    2016031 2013 1 167.20854  406.4096 19.739897 2
                    2016031 2016 1 152.28427  345.1777  12.18274 2
                    2016032 2013 1 116.11704  464.4682 17.417557 1
                    2016032 2016 1 263.95938  324.8731  13.19797 3
                    2016033 2013 1 185.78726  348.3511  25.54575 1
                    2016033 2016 1  314.7208    355.33  20.30457 1
                    2016034 2016 1  203.0457    355.33 15.228426 2
                    2016034 2013 1 139.34045  406.4096 19.739897 2
                    2016035 2013 1 162.56386  336.7394  5.805852 1
                    2016035 2016 1  243.6548  406.0914  20.30457 1
                    2016036 2016 1 233.50253  365.4822 17.258883 2
                    2016036 2013 1 162.56386 174.17557 13.934045 0
                    2016037 2016 1 213.19797    355.33 15.228426 1
                    2016037 2013 1 185.78726  290.2926 15.095216 1
                    2016038 2016 1 263.95938    355.33  24.36548 2
                    2016038 2013 1 162.56386  278.6809  5.805852 0
                    2016039 2016 1  324.8731  406.0914 22.335026 1
                    2016039 2013 1  232.2341  336.7394  23.22341 1
                    2016040 2016 1  365.4822  385.7868 17.258883 2
                    2016040 2013 1  278.6809 174.17557 17.417557 0
                    2016041 2013 1 162.56386  290.2926 16.256386 1
                    2016041 2016 1  253.8071  456.8528  27.41117 1
                    2016042 2013 1 130.05109  278.6809  9.289363 0
                    2016042 2016 1 284.26395    355.33  18.27411 2
                    2016043 2016 1  324.8731  406.0914 15.228426 1
                    2016043 2013 1 174.17557  336.7394  6.967022 1
                    2016044 2016 1 223.35025  426.3959 65.989845 2
                    2016044 2013 1 139.34045 174.17557  46.44682 0
                    2016045 2016 1 233.50253    355.33  5.076142 3
                    2016045 2013 1 162.56386  278.6809 11.611704 0
                    2016046 2016 1 284.26395  335.0254  12.18274 2
                    2016046 2013 1 185.78726  336.7394  5.805852 1
                    2016047 2016 0  446.7005 304.56854  18.27411 2
                    2016047 2013 0  394.7979  278.6809  9.289363 0
                    2016048 2013 0  603.8086  336.7394  6.967022 1
                    2016048 2016 0  690.3553    355.33 15.228426 1
                    2016049 2016 0 263.95938 284.26395  5.076142 1
                    2016049 2013 0  209.0107  290.2926 11.611704 1
                    2016050 2016 0  203.0457  375.6345 17.258883 1
                    2016050 2013 0 162.56386  336.7394 13.934045 1
                    end
                    ------------------ copy up to and including the previous line ------------------

                    Listed 100 out of 300 observations
                    Use the count() option to list more

                    Comment


                    • #11
                      The following code will get you started:

                      Code:
                      collapse (mean) usd*, by(trained year)
                      ds usd*
                      local outcomes `r(varlist)'
                      reshape wide usd*, i(year) j(trained)
                      
                      foreach v of local outcomes {
                          local content: subinstr local v "usd" ""
                          label var `v'0 "`content' (usd) untrained"
                          label var `v'1 "`content' (usd) trained"
                          graph twoway connect `v'* year, name(`content', replace)
                      }
                      You may want to add some options to the -graph twoway connect- command to customize the appearance of the graphs. Also you may want to stylize the variable labels according to your own tastes.

                      Note: The code assumes that your 0 and 1 in the trained variable correspond to untrained and trained, respectively.

                      Comment


                      • #12
                        Thank Clyde for your quick feedback.I will try the code and will likely come back to you for further guidance.

                        Comment


                        • #13
                          Dear Clyde,

                          Thanks it works.Could you now show me a standalone code for the variables 'employees' and 'usdcapital'.What about if you wanted to show an imaginary counterfactual position (in dotted line) for the trained for each of these two variables.
                          Last edited by henry mwangi; 03 Jul 2018, 00:25.

                          Comment


                          • #14
                            Could you now show me a standalone code for the variables 'employees' and 'usdcapital'.
                            Just change -ds usd*- to -ds employees usdcapital-.

                            What about if you wanted to show an imaginary counterfactual position (in dotted line) for the trained for each of these two variables
                            I don't understand what you mean by this.

                            Comment


                            • #15
                              Thanks Clyde,

                              As for the other request, i will attach a pictorial representation of what i am trying to build.

                              Comment

                              Working...
                              X