Announcement

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

  • #16
    Thank you very much Clyde!
    I have still some issues. I used your code and it generated three graphs. So, I have one graph for the group which is unaffected (no treatment/control group) and two graphs for the treatments groups (starting 2014 and starting 2015). Does this make sense?

    Comment


    • #17
      Yes, it does make sense. If, however, you would like to combine the two graphs for the 2014 starters and 2015 starters, you can revise the code along these lines:
      Code:
      by CompanyName (PeriodType), sort: egen first_year_effect = ///
      min(cond(in_effect, PeriodType, .))
      label define group 0 "Never Affected" 1 "Affected"
      gen byte group:group = !missing(first_year_effect)
      
      collapse (mean) RWATotalAssets , by ( group PeriodType )
      reshape wide RWATotalAssets , i( PeriodType ) j( group )
      graph twoway line RWATotalAssets* PeriodType
      The main problem, however, will be that the point on the affected line in 2014 will be a mix of affected and still unaffected, so really not interpretable.




      Comment


      • #18
        Hello,
        I am currently doing my dissertation on the effect of minimum unit pricing in Scotland on the price of alcohol, the total volume of alcohol consumption, and average unit and liters of alcohol intake. I am going to run a difference in difference model and i wanted to test for a parallel trend assumption and graph it. Can anyone please advise me on the code I will need to use?
        Thanks
        Averkios
        Click image for larger version

Name:	datastatata.png
Views:	1
Size:	78.2 KB
ID:	1593002

        Comment


        • #19
          Please read the Forum FAQ for excellent advice on how to get the most from your Statalist experience. The use of screenshots to show example data is explicitly discouraged, for several good reasons. The screenshots are often unreadable--this one is just barely readable when highly magnified, at least on my setup. Even when they are readable, they do not convey metadata that may be important for the solution of your problem. And, perhaps most important, there is no reasonable way to import data from a screenshot into Stata in order to develop and test code. The helpful way to show example data is to use the -dataex- command. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

          In addition to showing your example data, you will need to explain more about your project. You will need to explain what each of the variables you are using is (your variable names may convey obvious meaning to you, but not so much to others). And you certainly need to indicate when minimum unit pricing was introduced in Scotland. Also, I assume from what you write that Scotland is the treatment group and any other countries are control groups--but you should state that explicitly, or, if it isn't correct, explain how you identify the treatment and control countries. If there is more than one treatment country, did they all begin minimum unit pricing at the same time? If not, what in the data indicates the onset of minimum unit pricing in each country?

          Comment


          • #20
            Hello,
            Thank you Clyde very much i had no idea how to export the data. So my paper is based on measuring the effect minimum unit pricing had on alcohol price average consumption and the total volume. The policy was implemented on the 1 may 2018 but due to research reasons to ease myself, i will assume the policy was implemented on 1 January 2018. Below i show the labels of each variable. In the first part I will conduct a diff in diff, and i wanted to showcase a parallel trend assumption graph to show that actually England and Wales are a good control group. Any advice would be helpful.
            Thanks
            Averkios

            avgconsunitsoff "AverageAlcoholConsumptionUnitsOff-Trade"
            avgconsltroff "AverageAlcoholConsumptionLtrOff-Trade"
            totalvlmoff "TotalAlcoholVolumeOff-Trade"
            avgalcpoff "AverageAlcoholPriceOff-Trade"
            avgalcpt "AverageAlcoholPriceOn&OFf-Trade"
            totalvlmt "TotalAlcoholVolumeOn&Off-Trade"
            avgconsltrst "AverageAlcoholConsumptionLtrOn&Off-Trade"
            avgconsunitst "AverageAlcoholConsumptionUnitsOn&Off-Trade"
            alchospadm "Alcohol-related hospital admissions"
            acuteint "Acute intoxication due to alcohol intake"
            population "Entire population estimate"
            proportiond "Estimated proportion of adult drinkers"
            "Estimated adult drinker population"
            input int year str8 country float(avgconsunitsoff avgconsltroff totalvlmoff avgalcpoff avgconsunitst avgconsltrst totalvlmt avgalcpt) long population float proportiond double drinkingpop long alchospadm int acuteint float(YearD CountryD Diff _diff)
            2000 "EngWales" 514.79065 5.147907 213991.3 .3893808 9.868109 986.8109 410203.5 .6307347 41568600 90 37411740 . . 0 0 0 0
            2001 "EngWales" 543.3936 5.433936 227490.4 .3859698 10.14759 1014.759 424826.3 .6407194 41864752 88 36840981.76 . . 0 0 0 0
            2002 "EngWales" 561.6189 5.616189 236735.14 .3856243 10.30378 1030.3779 434327.75 .6481868 42152278 88 37094004.64 . . 0 0 0 0
            2003 "EngWales" 578.21014 5.782102 245374.47 .3901539 10.398236 1039.8236 441268.9 .6594344 42436900 89 37768841 . . 0 0 0 0
            2004 "EngWales" 589.84705 5.898471 252217.1 .3924679 10.423694 1042.3694 445714.5 .669508 42759747 88 37628577.36 236770 9760 0 0 0 0
            2005 "EngWales" 609.3009 6.093009 263212.2 .39673 10.483427 1048.3427 452874.1 .6790578 43199048 86.99779 37582215.58 253370 12240 0 0 0 0
            2006 "EngWales" 611.5901 6.115901 266551.03 .40017945 10.398604 1039.8605 453205.3 .6949785 43583285 86.5972 37741903.29 277060 15360 0 0 0 0
            2007 "EngWales" 629.9857 6.299857 277261.63 .4044064 10.294744 1029.4745 453079.8 .6976805 44010784 87.20243 38378474.31 287450 15860 0 0 0 0
            2008 "EngWales" 625.3168 6.253168 277827.88 .4189067 9.868193 986.8192 438443.2 .7166591 44429942 85.88465 38158500.86 293520 15780 0 0 0 0
            2009 "EngWales" 631.8096 6.318097 282888.9 .4361536 9.752556 975.2556 436664.7 .7286623 44774391 85.10242 38104092.82 300930 15390 0 0 0 0
            2010 "EngWales" 630.8068 6.308067 284977.28 .4522443 9.567835 956.7835 432242.7 .7481729 45176640 84.73016 38278240.49 315870 17540 0 0 0 0
            2011 "EngWales" 623.0678 6.230678 284025.2 .48290434 9.356197 935.6196 426501.8 .7985248 45584956 83 37835513.48 325910 17770 0 0 0 0
            2012 "EngWales" 613.7817 6.137817 281609.28 .5021546 9.171845 917.1845 420813.6 .8349898 45881018 81.698 37483874.09 327190 17610 0 0 0 0
            2013 "EngWales" 610.0798 6.100798 281758.2 .52371943 9.008068 900.8069 416027.1 .8573536 46183826 82.344 38029609.68 321660 15900 0 0 0 0
            2014 "EngWales" 615.7837 6.157837 286648.9 .5307747 9.001105 900.1106 419003.8 .8714793 46550257 81.69073 38027248.54 329970 16750 0 0 0 0
            2015 "EngWales" 622.3548 6.223548 292040.03 .5322524 9.007735 900.7735 422688.1 .8882245 46925010 82.8 38853908.28 330010 16070 0 0 0 0
            2016 "EngWales" 624.3541 6.24354 295288.47 .5345036 8.981342 898.1342 424772.9 .8973002 47295038 80.8 38214390.7 339280 16320 0 0 0 0
            2017 "EngWales" 630.0804 6.300804 299586.63 .55171394 8.974834 897.4834 426729.7 .9188067 47547364 81.5 38751102 337110 14160 0 0 0 0
            2018 "EngWales" 648.8198 6.488198 310166 .5633827 9.127992 912.7992 436360.4 .9362261 47804642 81.9 39152002 337870 13700 1 0 0 0
            2019 "EngWales" 654.9763 6.549763 315060 .5736653 9.146619 914.6619 439975.25 .9545288 48102501 81.9 39395948 357660 15170 1 0 0 0
            2000 "Sct" 649.6078 6.496078 26492.156 .3867758 10.897624 1089.7625 44442.44 .6140769 4078177 89.72 3658940.404 . . 0 1 0 0
            2001 "Sct" 663.8988 6.638988 27178.86 .3867254 11.084907 1108.4906 45379.68 .6274047 4093826 89.54 3665611.8 25782 8220 0 1 0 0
            2002 "Sct" 678.5484 6.785484 27876.01 .3857644 10.986223 1098.6223 45133.42 .6102332 4108183 89.36 3671072.329 27072 8745 0 1 0 0
            2003 "Sct" 701.8754 7.018754 28934.06 .3885694 11.27755 1127.7549 46490.49 .6175265 4122393 88.9367 3666320.295 27960 8346 0 1 0 0
            2004 "Sct" 715.2648 7.152648 29658.84 .38729465 11.50004 1150.004 47685.54 .6247438 4146554 89 3690433.06 27687 7497 0 1 0 0
            2005 "Sct" 732.8439 7.328439 30619.27 .3947784 11.66955 1166.955 48757.05 .6413528 4178143 88.8 3710190.984 29094 7053 0 1 0 0
            2006 "Sct" 739.8911 7.398911 31126.217 .3988899 11.641888 1164.1888 48975.85 .6580011 4206865 88.6 3727282.39 28758 6579 0 1 0 0
            2007 "Sct" 755.9628 7.559628 32101.02 .40030175 11.691287 1169.1287 49645.59 .6732001 4246375 88.4 3753795.5 29661 7116 0 1 0 0
            2008 "Sct" 766.1778 7.661778 32802.04 .4130346 11.6125 1161.2501 49716.1 .684679 4281257 88.2836 3779647.805 31005 7866 0 1 0 0
            2009 "Sct" 786.3604 7.863605 33905.15 .4304926 11.58546 1158.546 49952.51 .7017193 4311655 87.1363 3757016.636 30483 7491 0 1 0 0
            2010 "Sct" 790.5214 7.905214 34073.844 .4498936 11.468416 1146.8416 49553.82 .7297109 4344402 85.3275 3706969.617 28644 6852 0 1 0 0
            2011 "Sct" 782.8397 7.828397 34318.1 .4769129 11.053094 1105.3094 48454.52 .7699904 4383797 85.5175 3748913.599 28026 7176 0 1 0 0
            2012 "Sct" 740.6321 7.406321 32580.21 .4973112 10.591862 1059.1863 46593.33 .8081049 4398974 85.0143 3739756.953 27690 9063 0 1 0 0
            2013 "Sct" 734.7968 7.347968 32449.514 .52005833 10.333633 1033.3632 45634.57 .8241854 4416121 83.7044 3696487.586 25983 8370 0 1 0 0
            2014 "Sct" 745.8414 7.458414 33089.695 .52344036 10.394287 1039.4287 46114.87 .8458828 4436559 84.0854 3730498.381 26100 8025 0 1 0 0
            2015 "Sct" 745.514 7.455141 33255.43 .52493715 10.349268 1034.9268 46165.37 .8677589 4460738 84.2505 3758194.069 25254 7455 0 1 0 0
            2016 "Sct" 735.9532 7.359533 33035.344 .5279879 10.24759 1024.759 45999.21 .8827349 4488783 83.8 3761600.154 25197 7347 0 1 0 0
            2017 "Sct" 740.387 7.40387 33371.89 .5469399 10.256257 1025.6257 46228.62 .8962643 4507358 83.1 1270320 25503 7584 0 1 0 0
            2018 "Sct" 720.0552 7.200552 32536.4 .5943602 9.939983 993.9983 44914.79 .9504272 4518598 83.6 1193197.5 24906 7425 1 1 1 1
            2019 "Sct" 721.7499 7.217499 32716.43 .6208439 9.940753 994.0753 45060.76 .9875119 4532932

            Comment


            • #21
              So the core of getting parallel trends graphs is the following:

              Code:
              keep if year < 2018
              assert inlist(country, "Sct", "EngWales")
              isid country year
              ds country year, not
              reshape wide `r(varlist)', i(year) j(country) string
              graph twoway connected avgconsunitsoff* year
              Note: The -graph command- will show you the parallel trends for avgconsunitsoff. I notice you have a number of consumption variables, some in units and some in liters, some "off trade" and some "on and off trade." I have no idea what the last two mean. And I don't know if you want to use them separately or add or average them or what. Anyway, the point is, the after the -reshape wide- command you can reconfigure this data in whatever way makes sense to get the actual variables you want to show parallel trends on. Then use those variables instead of avgconsunitsoff* in the -graph twoway connected- command.

              Comment


              • #22
                Thank you very much sir, appreciated

                Comment


                • #23
                  Dear Clyde

                  I am trying to replicate the code but for a categorical outcome variable. I used the "contract" command in stata but I am missing the procedures.

                  Originally posted by Clyde Schechter View Post
                  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.

                  This is the code I used for the cost
                  Code:
                  collapse (mean) cost, by(treat year)
                  ds cost
                  local outcomes `r(varlist)'
                  reshape wide cost, i(year) j(treat)
                  
                  foreach v of local outcomes {
                      local content: subinstr local v "cost" ""
                      label var `v'0 "`content' (cost) comparison"
                      label var `v'1 "`content' (cost) treatment"
                      graph twoway connect `v'* year, name(`content', replace) ytitle("Average basic cost")
                  }

                  For the categorical variable (lifesat), I'm trying to plot the trend for the percentage that are completely satisfied (lifesat=7).
                  However, I tried to modify the code using "contract" but I couldn't go beyond the reshape option

                  Code:
                  contract year treat lifesat, nomiss
                  keep lifesat==7
                  local outcomes `r(varlist)'
                  reshape wide lifesat, i(year) j(t4)
                  foreach v of local outcomes {
                      local content: subinstr local v "lifesat" ""
                      label var `v'0 "`content' comparison group (lifesat)"
                      label var `v'1 "`content' treatment group (lifesat) "
                      graph twoway connect `v'* year, name(`content', replace)
                  }

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input float(year cost treat lifesat post id)
                  2015  7.8 0 6 0    775210
                  2017  7.7 1 6 1    938410
                  2011    6 1 . 0   1330090
                  2012 6.28 0 5 0   1330090
                  2013 6.31 1 4 0   1330090
                  2015  7.5 0 4 0   1330090
                  2014 7.68 0 3 0   3667930
                  2016    9 0 2 1   3667930
                  2014  6.5 1 4 0   4134410
                  2016 7.25 1 7 1   5253690
                  2017 7.75 1 1 1   5253690
                  2016  8.5 0 2 1   5777290
                  2011    7 0 7 0   7830890
                  2015 7.82 0 5 0 136005456
                  2011 6.53 0 4 0 136008176
                  2015 7.66 0 4 0 136008176
                  2016 7.62 0 6 1 136008176
                  2011 6.08 1 . 0 136012272
                  2012 6.21 0 5 0 136012272
                  2015 7.66 0 6 0 136017696
                  2013 6.31 1 5 0 136021776
                  2015  8.6 0 2 0 136021776
                  2014  6.8 0 6 0 136035376
                  2015  7.2 1 6 0 136035376
                  2016  7.8 0 6 1 136057136
                  2011 6.48 0 6 0 136057152
                  2011  6.7 0 6 0 136059856
                  2014    5 1 7 0 136059872
                  2011 6.08 1 6 0 136074816
                  2013  6.3 1 6 0 136074816
                  2014  6.5 1 5 0 136074816
                  2012 6.64 0 3 0 136112896
                  2014 6.64 0 3 0 136112896
                  2015 6.84 1 4 0 136112896
                  2012 4.89 1 5 0 136112912
                  2013 7.26 0 5 0 136126496
                  2012  7.2 0 4 0 136131936
                  2011  6.5 0 3 0 136133296
                  2012 6.93 0 4 0 136133296
                  2014 7.22 0 5 0 136133296
                  2011  5.5 1 6 0 136136032
                  2012  6.9 0 6 0 136136032
                  2014  6.5 1 6 0 136136032
                  2011 6.08 1 3 0 136142816
                  2012  6.3 0 1 0 136142816
                  2014 7.37 0 5 0 136142816
                  2015  8.5 0 3 0 136142816
                  2016  8.5 0 3 1 136142816
                  2014  5.6 1 5 0 136182256
                  2011 6.33 0 5 0 136187696
                  2016 7.59 0 7 1 136205392
                  2011 6.29 0 6 0 136232576
                  2012 6.55 0 6 0 136232576
                  2013 6.69 0 . 0 136232576
                  2014  6.7 0 6 0 136232576
                  2016  8.2 0 5 1 136232576
                  2015  8.3 0 6 0 136242096
                  2016  8.5 0 6 1 136242096
                  2014 5.13 1 7 0 136242112
                  2016  3.7 1 7 1 136242112
                  2011    7 0 2 0 136243456
                  2012  6.4 0 5 0 136243456
                  2014    7 0 5 0 136243456
                  2015  7.5 0 3 0 136243456
                  2016  7.2 1 2 1 136243456
                  2013 5.03 1 7 0 136250272
                  2014  6.5 1 6 0 136265232
                  2015    8 0 4 0 136266576
                  2011 6.08 1 . 0 136281536
                  2015  8.6 0 3 0 136282896
                  2014    6 1 3 0 136282912
                  2015 7.77 0 6 0 136301936
                  2016 8.22 0 6 1 136301936
                  2011    7 0 6 0 136301952
                  2012 6.38 0 6 0 136301952
                  2011 7.07 0 6 0 136310096
                  2012 7.15 0 . 0 136310096
                  2015 7.72 0 6 0 136310096
                  2016 7.29 1 2 1 136310096
                  2011  6.7 0 4 0 136310112
                  2012  6.4 0 . 0 136310112
                  2011 6.08 1 6 0 136310112
                  2012 6.19 0 . 0 136310112
                  2014  6.5 1 6 0 136310112
                  2011 4.98 1 6 0 136310128
                  2015  6.7 1 7 0 136310128
                  2015 7.75 0 4 0 136333216
                  2015  8.5 0 5 0 136335936
                  2016  8.5 0 6 1 136335936
                  2011    6 1 2 0 136346816
                  2012 6.47 0 6 0 136346816
                  2013  6.5 0 6 0 136346816
                  2016    9 0 5 1 136361776
                  2012    7 0 5 0 136386256
                  2016 6.95 1 4 1 136394432
                  2011 6.89 0 6 0 136395776
                  2016  8.6 0 6 1 136395792
                  2012 6.36 0 6 0 136395792
                  2015  7.5 0 6 0 136395792
                  2011 6.35 0 6 0 136428416
                  end
                  label values cost a_basrate
                  label values lifesat a_sclfsato
                  label def a_sclfsato 1 "completely dissatisfied", modify
                  label def a_sclfsato 2 "mostly dissatisfied", modify
                  label def a_sclfsato 3 "somewhat dissatisfied", modify
                  label def a_sclfsato 4 "Neither Sat nor Dissat", modify
                  label def a_sclfsato 5 "somewhat satisfied", modify
                  label def a_sclfsato 6 "mostly satisfied", modify
                  label def a_sclfsato 7 "completely satisfied", modify
                  Last edited by Lateef Akanni; 07 Feb 2021, 08:54.

                  Comment


                  • #24
                    Code:
                    gen byte completely_satisfied = 7.lifesat
                    collapse (mean) completely_satisfied, by(treat year)
                    reshape wide completely_satisfied, i(year) j(treat)
                    graph twoway line completely_satisfied* year

                    Comment


                    • #25
                      Thanks so much, Clyde

                      Comment


                      • #26
                        Hello again,
                        I want to run a difference in difference model with the available data to test how the minimum unit pricing in Scotland in 2018 affected the price of alcohol, total volume of alcohol, and the average consumption in units
                        and litrs ( all for on-trade,off-trade and the sum of the two).Scotland is the treatment and England & Wales the control group and the policy was enforced on the beginning of 2018. I have run a difference in difference models already but i wanted to cross check it. How would you do it please let me know.
                        Thanks
                        Averkios


                        avgconsunitsoff "AverageAlcoholConsumptionUnitsOff-Trade"
                        avgconsltroff "AverageAlcoholConsumptionLtrOff-Trade"
                        totalvlmoff "TotalAlcoholVolumeOff-Trade"
                        avgalcpoff "AverageAlcoholPriceOff-Trade"
                        avgalcpt "AverageAlcoholPriceOn&OFf-Trade"
                        totalvlmt "TotalAlcoholVolumeOn&Off-Trade"
                        avgconsltrst "AverageAlcoholConsumptionLtrOn&Off-Trade"
                        avgconsunitst "AverageAlcoholConsumptionUnitsOn&Off-Trade"
                        alchospadm "Alcohol-related hospital admissions"
                        acuteint "Acute intoxication due to alcohol intake"
                        population "Entire population estimate"
                        proportiond "Estimated proportion of adult drinkers"
                        "Estimated adult drinker population"
                        input int year str8 country float(avgconsunitsoff avgconsltroff totalvlmoff avgalcpoff avgconsunitst avgconsltrst totalvlmt avgalcpt) long population float proportiond double drinkingpop long alchospadm int acuteint float(YearD CountryD Diff _diff)
                        2000 "EngWales" 514.79065 5.147907 213991.3 .3893808 9.868109 986.8109 410203.5 .6307347 41568600 90 37411740 . . 0 0 0 0
                        2001 "EngWales" 543.3936 5.433936 227490.4 .3859698 10.14759 1014.759 424826.3 .6407194 41864752 88 36840981.76 . . 0 0 0 0
                        2002 "EngWales" 561.6189 5.616189 236735.14 .3856243 10.30378 1030.3779 434327.75 .6481868 42152278 88 37094004.64 . . 0 0 0 0
                        2003 "EngWales" 578.21014 5.782102 245374.47 .3901539 10.398236 1039.8236 441268.9 .6594344 42436900 89 37768841 . . 0 0 0 0
                        2004 "EngWales" 589.84705 5.898471 252217.1 .3924679 10.423694 1042.3694 445714.5 .669508 42759747 88 37628577.36 236770 9760 0 0 0 0
                        2005 "EngWales" 609.3009 6.093009 263212.2 .39673 10.483427 1048.3427 452874.1 .6790578 43199048 86.99779 37582215.58 253370 12240 0 0 0 0
                        2006 "EngWales" 611.5901 6.115901 266551.03 .40017945 10.398604 1039.8605 453205.3 .6949785 43583285 86.5972 37741903.29 277060 15360 0 0 0 0
                        2007 "EngWales" 629.9857 6.299857 277261.63 .4044064 10.294744 1029.4745 453079.8 .6976805 44010784 87.20243 38378474.31 287450 15860 0 0 0 0
                        2008 "EngWales" 625.3168 6.253168 277827.88 .4189067 9.868193 986.8192 438443.2 .7166591 44429942 85.88465 38158500.86 293520 15780 0 0 0 0
                        2009 "EngWales" 631.8096 6.318097 282888.9 .4361536 9.752556 975.2556 436664.7 .7286623 44774391 85.10242 38104092.82 300930 15390 0 0 0 0
                        2010 "EngWales" 630.8068 6.308067 284977.28 .4522443 9.567835 956.7835 432242.7 .7481729 45176640 84.73016 38278240.49 315870 17540 0 0 0 0
                        2011 "EngWales" 623.0678 6.230678 284025.2 .48290434 9.356197 935.6196 426501.8 .7985248 45584956 83 37835513.48 325910 17770 0 0 0 0
                        2012 "EngWales" 613.7817 6.137817 281609.28 .5021546 9.171845 917.1845 420813.6 .8349898 45881018 81.698 37483874.09 327190 17610 0 0 0 0
                        2013 "EngWales" 610.0798 6.100798 281758.2 .52371943 9.008068 900.8069 416027.1 .8573536 46183826 82.344 38029609.68 321660 15900 0 0 0 0
                        2014 "EngWales" 615.7837 6.157837 286648.9 .5307747 9.001105 900.1106 419003.8 .8714793 46550257 81.69073 38027248.54 329970 16750 0 0 0 0
                        2015 "EngWales" 622.3548 6.223548 292040.03 .5322524 9.007735 900.7735 422688.1 .8882245 46925010 82.8 38853908.28 330010 16070 0 0 0 0
                        2016 "EngWales" 624.3541 6.24354 295288.47 .5345036 8.981342 898.1342 424772.9 .8973002 47295038 80.8 38214390.7 339280 16320 0 0 0 0
                        2017 "EngWales" 630.0804 6.300804 299586.63 .55171394 8.974834 897.4834 426729.7 .9188067 47547364 81.5 38751102 337110 14160 0 0 0 0
                        2018 "EngWales" 648.8198 6.488198 310166 .5633827 9.127992 912.7992 436360.4 .9362261 47804642 81.9 39152002 337870 13700 1 0 0 0
                        2019 "EngWales" 654.9763 6.549763 315060 .5736653 9.146619 914.6619 439975.25 .9545288 48102501 81.9 39395948 357660 15170 1 0 0 0
                        2000 "Sct" 649.6078 6.496078 26492.156 .3867758 10.897624 1089.7625 44442.44 .6140769 4078177 89.72 3658940.404 . . 0 1 0 0
                        2001 "Sct" 663.8988 6.638988 27178.86 .3867254 11.084907 1108.4906 45379.68 .6274047 4093826 89.54 3665611.8 25782 8220 0 1 0 0
                        2002 "Sct" 678.5484 6.785484 27876.01 .3857644 10.986223 1098.6223 45133.42 .6102332 4108183 89.36 3671072.329 27072 8745 0 1 0 0
                        2003 "Sct" 701.8754 7.018754 28934.06 .3885694 11.27755 1127.7549 46490.49 .6175265 4122393 88.9367 3666320.295 27960 8346 0 1 0 0
                        2004 "Sct" 715.2648 7.152648 29658.84 .38729465 11.50004 1150.004 47685.54 .6247438 4146554 89 3690433.06 27687 7497 0 1 0 0
                        2005 "Sct" 732.8439 7.328439 30619.27 .3947784 11.66955 1166.955 48757.05 .6413528 4178143 88.8 3710190.984 29094 7053 0 1 0 0
                        2006 "Sct" 739.8911 7.398911 31126.217 .3988899 11.641888 1164.1888 48975.85 .6580011 4206865 88.6 3727282.39 28758 6579 0 1 0 0
                        2007 "Sct" 755.9628 7.559628 32101.02 .40030175 11.691287 1169.1287 49645.59 .6732001 4246375 88.4 3753795.5 29661 7116 0 1 0 0
                        2008 "Sct" 766.1778 7.661778 32802.04 .4130346 11.6125 1161.2501 49716.1 .684679 4281257 88.2836 3779647.805 31005 7866 0 1 0 0
                        2009 "Sct" 786.3604 7.863605 33905.15 .4304926 11.58546 1158.546 49952.51 .7017193 4311655 87.1363 3757016.636 30483 7491 0 1 0 0
                        2010 "Sct" 790.5214 7.905214 34073.844 .4498936 11.468416 1146.8416 49553.82 .7297109 4344402 85.3275 3706969.617 28644 6852 0 1 0 0
                        2011 "Sct" 782.8397 7.828397 34318.1 .4769129 11.053094 1105.3094 48454.52 .7699904 4383797 85.5175 3748913.599 28026 7176 0 1 0 0
                        2012 "Sct" 740.6321 7.406321 32580.21 .4973112 10.591862 1059.1863 46593.33 .8081049 4398974 85.0143 3739756.953 27690 9063 0 1 0 0
                        2013 "Sct" 734.7968 7.347968 32449.514 .52005833 10.333633 1033.3632 45634.57 .8241854 4416121 83.7044 3696487.586 25983 8370 0 1 0 0
                        2014 "Sct" 745.8414 7.458414 33089.695 .52344036 10.394287 1039.4287 46114.87 .8458828 4436559 84.0854 3730498.381 26100 8025 0 1 0 0
                        2015 "Sct" 745.514 7.455141 33255.43 .52493715 10.349268 1034.9268 46165.37 .8677589 4460738 84.2505 3758194.069 25254 7455 0 1 0 0
                        2016 "Sct" 735.9532 7.359533 33035.344 .5279879 10.24759 1024.759 45999.21 .8827349 4488783 83.8 3761600.154 25197 7347 0 1 0 0
                        2017 "Sct" 740.387 7.40387 33371.89 .5469399 10.256257 1025.6257 46228.62 .8962643 4507358 83.1 1270320 25503 7584 0 1 0 0
                        2018 "Sct" 720.0552 7.200552 32536.4 .5943602 9.939983 993.9983 44914.79 .9504272 4518598 83.6 1193197.5 24906 7425 1 1 1 1
                        2019 "Sct" 721.7499 7.217499 32716.43 .6208439 9.940753 994.0753 45060.76 .9875119 4532932

                        Comment


                        • #27
                          Originally posted by Clyde Schechter View Post
                          Yes, it does make sense. If, however, you would like to combine the two graphs for the 2014 starters and 2015 starters, you can revise the code along these lines:
                          Code:
                          by CompanyName (PeriodType), sort: egen first_year_effect = ///
                          min(cond(in_effect, PeriodType, .))
                          label define group 0 "Never Affected" 1 "Affected"
                          gen byte group:group = !missing(first_year_effect)
                          
                          collapse (mean) RWATotalAssets , by ( group PeriodType )
                          reshape wide RWATotalAssets , i( PeriodType ) j( group )
                          graph twoway line RWATotalAssets* PeriodType
                          The main problem, however, will be that the point on the affected line in 2014 will be a mix of affected and still unaffected, so really not interpretable.



                          Thanks Clyde, it worked perfectly. I totally understand your point regarding the interpretation of the two instead of three graphs.
                          I´m still working on this project and now I want to do the regression.
                          I tried using the same code which you posted initially for Johannes.

                          Originally posted by Clyde Schechter View Post
                          This variable is actually very analogous to the interaction term in a DID model. You now do the following regression:

                          Code:
                          encode country, gen country_num
                          xtset country_num year
                          xtreg av_wgi in_effect i.year /* OTHER PREDICTORS HERE */, fe
                          .
                          Problem is that I can not totally follow why we have to include the year and country variable into our regression.
                          In addition, if use the code on my dataset it does not work and shows: "option generate incorrectly specified"

                          Code:
                          encode Country, generate Country_num
                          xtset Country_num PeriodType
                          xtreg RWATotalAssets in_effect i.PeriodType, fe
                          Thanks for your help.
                          Last edited by Abiodun Olatunji; 24 Mar 2021, 09:48.

                          Comment


                          • #28
                            Problem is that I can not totally follow why we have to include the year and country variable into our regression.
                            You may not have to in your situation. It depends. When you have a true difference-in-differences design, where there is a single starting time for the intervention in all of the treatment group, then the analysis requires incorporation of a variable indicating treated vs untreated status, and another incorporating pre-intervention era vs post-intervention era, and their interaction. But in the generalizedI difference in differences design, which is used when different units begin treatment at different times, to get the correct treatment effect estimate you must include indicators for both the unit-of-treatment (firm, country, whatever) and a fine-grained time period (since there is no "pre-treatment era" that applies to every entity in the data.) For more information about generalized difference-in-differences, see https://www.annualreviews.org/doi/pd...-040617-013507.

                            In addition, if use the code on my dataset it does not work and shows: "option generate incorrectly specified"
                            There is an error in that code. The first command should be:
                            Code:
                            encode Country, generate(Country_num)
                            The parentheses are required for specifying the value of the -generate()- option.

                            Comment


                            • #29
                              Thanks Clyde!

                              Entering following code:

                              Code:
                              xtset Country_num PeriodType
                              Provides me following error: "repeated time values within panel"

                              My dataset contains for every company multiple observations from 2008-2018. So I oviously have repeating time values within my panel. Is this error code aiming on this or is there some other problem?

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input str139 CompanyName long ID int PeriodType str3 Country float(RWA in_effect) long Country_num
                              "AMP Bank Limited"                                1000419 2008 "AUS"          . 0 1
                              "Bank of Sydney Ltd"                              1155710 2008 "AUS"          . 0 1
                              "IMB Ltd"                                         1005780 2008 "AUS"          . 0 1
                              "National Australia Bank Limited"                  108299 2008 "AUS"          . 0 1
                              "Newcastle Permanent Building Society Limited"    1021613 2008 "AUS"          . 0 1
                              "Bank of Queensland Limited"                       113011 2008 "AUS"          . 0 1
                              "Macquarie Bank Limited"                           111127 2008 "AUS"          . 0 1
                              "ING Bank (Australia) Limited"                    1005878 2008 "AUS"          . 0 1
                              "Police & Nurses Limited"                         1171610 2008 "AUS"          . 0 1
                              "HSBC Bank Australia Limited"                     1005465 2008 "AUS"          . 0 1
                              "Tasmanian Public Finance Corporation"            1011377 2008 "AUS"          . 0 1
                              "South Australian Government Financing Authority" 1010034 2008 "AUS"          . 0 1
                              "Westpac Banking Corporation"                      108729 2008 "AUS"          . 0 1
                              "Cuscal Limited"                                  1097832 2008 "AUS"          . 0 1
                              "Members Equity Bank Limited"                     1021960 2008 "AUS"          . 0 1
                              "Suncorp-Metway Limited"                           109542 2008 "AUS"          . 0 1
                              "B&E Ltd"                                         1021606 2008 "AUS"          . 0 1
                              "Heritage Bank Limited"                           1005350 2008 "AUS"          . 0 1
                              "Bendigo and Adelaide Bank Limited"                112028 2008 "AUS"          . 0 1
                              "Auswide Bank Ltd"                                1021617 2008 "AUS"          . 0 1
                              "Commonwealth Bank of Australia"                   107737 2008 "AUS"          . 0 1
                              "Hume Bank Limited"                               1021609 2008 "AUS"          . 0 1
                              "Australia and New Zealand Banking Group Limited"  111503 2008 "AUS"          . 0 1
                              "Credit Union Australia Limited"                  1056234 2008 "AUS"          . 0 1
                              "Maitland Mutual Building Society Limited"        1021612 2008 "AUS"          . 0 1
                              "Greater Bank Limited"                            1021607 2008 "AUS"          . 0 1
                              "Macquarie Group Limited"                         1167911 2008 "AUS"          . 0 1
                              "Suncorp-Metway Limited"                           109542 2009 "AUS"   4.333585 0 1
                              "HSBC Bank Australia Limited"                     1005465 2009 "AUS"  4.1039047 0 1
                              "Credit Union Australia Limited"                  1056234 2009 "AUS"   2.517239 0 1
                              "Members Equity Bank Limited"                     1021960 2009 "AUS"   5.444168 0 1
                              "Bank of Queensland Limited"                       113011 2009 "AUS"   5.156281 0 1
                              "ING Bank (Australia) Limited"                    1005878 2009 "AUS"   3.794611 0 1
                              "Heritage Bank Limited"                           1005350 2009 "AUS"   4.258021 0 1
                              "Bendigo and Adelaide Bank Limited"                112028 2009 "AUS"   3.645112 0 1
                              "South Australian Government Financing Authority" 1010034 2009 "AUS"   2.418303 0 1
                              "AMP Bank Limited"                                1000419 2009 "AUS"   5.233776 0 1
                              "Cuscal Limited"                                  1097832 2009 "AUS"   2.510867 0 1
                              "Macquarie Bank Limited"                           111127 2009 "AUS" -.30863735 0 1
                              "Greater Bank Limited"                            1021607 2009 "AUS"   6.648091 0 1
                              "Auswide Bank Ltd"                                1021617 2009 "AUS"   4.518509 0 1
                              "Tasmanian Public Finance Corporation"            1011377 2009 "AUS"  1.3615093 0 1
                              "National Australia Bank Limited"                  108299 2009 "AUS"   3.260163 0 1
                              "Bank of Sydney Ltd"                              1155710 2009 "AUS"   4.188016 0 1
                              "Maitland Mutual Building Society Limited"        1021612 2009 "AUS"   6.332794 0 1
                              "Newcastle Permanent Building Society Limited"    1021613 2009 "AUS"   4.999148 0 1
                              "Police & Nurses Limited"                         1171610 2009 "AUS"   3.190403 0 1
                              "Macquarie Group Limited"                         1167911 2009 "AUS"  3.0331476 0 1
                              "IMB Ltd"                                         1005780 2009 "AUS"   5.249492 0 1
                              "Commonwealth Bank of Australia"                   107737 2009 "AUS"   3.585411 0 1
                              "B&E Ltd"                                         1021606 2009 "AUS"   3.746044 0 1
                              "Westpac Banking Corporation"                      108729 2009 "AUS"   3.474814 0 1
                              "Hume Bank Limited"                               1021609 2009 "AUS"  3.4196844 0 1
                              "Australia and New Zealand Banking Group Limited"  111503 2009 "AUS"    4.73309 0 1
                              "South Australian Government Financing Authority" 1010034 2010 "AUS"  1.4172156 0 1
                              "Tasmanian Public Finance Corporation"            1011377 2010 "AUS"   1.892838 0 1
                              "Hume Bank Limited"                               1021609 2010 "AUS"  3.7711644 0 1
                              "Macquarie Bank Limited"                           111127 2010 "AUS"  .16736577 0 1
                              "Heritage Bank Limited"                           1005350 2010 "AUS"   4.252008 0 1
                              "HSBC Bank Australia Limited"                     1005465 2010 "AUS"  4.3349476 0 1
                              "Greater Bank Limited"                            1021607 2010 "AUS"   4.523633 0 1
                              "Westpac Banking Corporation"                      108729 2010 "AUS"    3.51098 0 1
                              "IMB Ltd"                                         1005780 2010 "AUS"  4.2826414 0 1
                              "Commonwealth Bank of Australia"                   107737 2010 "AUS"   4.024962 0 1
                              "Bank of Queensland Limited"                       113011 2010 "AUS"   5.306478 0 1
                              "Auswide Bank Ltd"                                1021617 2010 "AUS"  4.5879936 0 1
                              "Macquarie Group Limited"                         1167911 2010 "AUS"  3.5453465 0 1
                              "Newcastle Permanent Building Society Limited"    1021613 2010 "AUS"   4.168674 0 1
                              "National Australia Bank Limited"                  108299 2010 "AUS"  3.5948234 0 1
                              "Suncorp-Metway Limited"                           109542 2010 "AUS"  4.1944127 0 1
                              "Bank of Sydney Ltd"                              1155710 2010 "AUS"   4.363027 0 1
                              "Police & Nurses Limited"                         1171610 2010 "AUS"   3.463485 0 1
                              "Credit Union Australia Limited"                  1056234 2010 "AUS"   2.978728 0 1
                              "Cuscal Limited"                                  1097832 2010 "AUS"  3.0657194 0 1
                              "AMP Bank Limited"                                1000419 2010 "AUS"   3.666301 0 1
                              "Bendigo and Adelaide Bank Limited"                112028 2010 "AUS"       3.82 0 1
                              "Members Equity Bank Limited"                     1021960 2010 "AUS"    3.97975 0 1
                              "ING Bank (Australia) Limited"                    1005878 2010 "AUS"   4.048666 0 1
                              "B&E Ltd"                                         1021606 2010 "AUS"   4.079609 0 1
                              "Australia and New Zealand Banking Group Limited"  111503 2010 "AUS"  4.1167617 0 1
                              "Maitland Mutual Building Society Limited"        1021612 2010 "AUS"  3.4424884 0 1
                              "Hume Bank Limited"                               1021609 2011 "AUS"   3.959112 0 1
                              "Members Equity Bank Limited"                     1021960 2011 "AUS"  3.8094144 0 1
                              "Tasmanian Public Finance Corporation"            1011377 2011 "AUS"   2.313603 0 1
                              "Westpac Banking Corporation"                      108729 2011 "AUS"   3.377143 0 1
                              "Bendigo and Adelaide Bank Limited"                112028 2011 "AUS"   3.471541 0 1
                              "Australia and New Zealand Banking Group Limited"  111503 2011 "AUS"  3.8753285 0 1
                              "IMB Ltd"                                         1005780 2011 "AUS"  4.4104314 0 1
                              "Maitland Mutual Building Society Limited"        1021612 2011 "AUS"   3.700477 0 1
                              "AMP Bank Limited"                                1000419 2011 "AUS"   3.370375 0 1
                              "ING Bank (Australia) Limited"                    1005878 2011 "AUS"   4.998162 0 1
                              "Credit Union Australia Limited"                  1056234 2011 "AUS"   3.205609 0 1
                              "Suncorp-Metway Limited"                           109542 2011 "AUS"   3.091818 0 1
                              "Macquarie Group Limited"                         1167911 2011 "AUS"     4.8456 0 1
                              "HSBC Bank Australia Limited"                     1005465 2011 "AUS"   5.312684 0 1
                              "Newcastle Permanent Building Society Limited"    1021613 2011 "AUS"  4.1356444 0 1
                              "Auswide Bank Ltd"                                1021617 2011 "AUS"  4.6198187 0 1
                              "South Australian Government Financing Authority" 1010034 2011 "AUS"  1.4382135 0 1
                              "Bank of Sydney Ltd"                              1155710 2011 "AUS"  4.4250975 0 1
                              "Heritage Bank Limited"                           1005350 2011 "AUS"   5.128567 0 1
                              end
                              label values Country_num Country_num
                              label def Country_num 1 "AUS", modify
                              Last edited by Abiodun Olatunji; 25 Mar 2021, 02:34.

                              Comment


                              • #30
                                Hi Clyde Schechter ,

                                I am taking advantage of this old thread asking a related question for visualizing the parallel trend assumption.

                                I have two group of companies and a policy intervention in 2018q1. The outcome variable of interest is sdresidual1.

                                I want to visualize the trend of the outcome variable before and after the policy, ideally plotting on a graph. I used your third suggestion in post #2. Nevertheless, it plots the average of sdresidual1. Indeed, if I plot I'm captuing the seasonality of my variable.

                                To be clearer: My aim si to plot dots (representing the averages of sdreidusl1) and add two trend lines by group. One for pre treatement and one for post ptreatement period for both groups. In this case, I can better isolate and visualize the effect of policty intervention with trend lines

                                Do you hav any suggestion on how to do the same graph but with trend lines?

                                Many thanks in advance for your time and suggestions

                                Here the data example:

                                Code:
                                * Example generated by -dataex-. To install: ssc install dataex
                                clear
                                input float(datacqtr treated sdresidual1)
                                204 0           .
                                205 0           .
                                206 0  .014890284
                                207 0  .014020506
                                208 0  .016691122
                                209 0  .017085187
                                210 0  .010816443
                                211 0  .015575575
                                212 0  .015730511
                                213 0  .016090017
                                214 0  .012449549
                                215 0   .01196941
                                216 0  .008263536
                                217 0   .01121567
                                218 0   .01091278
                                219 0  .010813504
                                220 0   .02556563
                                221 0   .04646164
                                222 0   .04795977
                                223 0   .04590715
                                224 0     .045267
                                225 0   .04569731
                                226 0  .009242511
                                227 0   .01027029
                                228 0  .011657882
                                229 0   .01197356
                                230 0  .012447027
                                231 0  .020500617
                                232 0   .02537457
                                233 0    .0185546
                                234 0   .01581371
                                235 0  .016161969
                                236 0  .015015014
                                237 0  .010408453
                                238 0  .011111812
                                239 0  .011446786
                                240 0   .01437524
                                241 0   .02267676
                                242 0  .016423613
                                243 0   .01914652
                                244 0  .018576972
                                203 0           .
                                219 0           .
                                223 0  .016176233
                                227 0   .01472257
                                231 0  .012751053
                                235 0   .01102333
                                239 0   .01083829
                                243 0  .012315964
                                202 0           .
                                203 0           .
                                204 0   .01382985
                                205 0   .02177825
                                206 0  .020065544
                                207 0   .02171749
                                208 0  .016854238
                                209 0  .019270774
                                210 0  .021455986
                                211 0   .02388353
                                212 0  .014966824
                                213 0  .011933112
                                214 0  .012230613
                                215 0   .00981619
                                216 0  .004675772
                                217 0 .0041497336
                                218 0  .011822327
                                219 0  .018556628
                                220 0  .015947262
                                221 0  .015270473
                                222 0   .01166334
                                223 0  .012700167
                                224 0  .015407815
                                225 0  .019437414
                                226 0   .02880695
                                227 0  .024347907
                                228 0  .013889073
                                229 0  .015860293
                                230 0  .020166647
                                231 0  .013739113
                                232 0  .011484974
                                233 0  .008525606
                                234 0  .016851015
                                235 0   .02553392
                                236 0   .02070523
                                237 0  .020652574
                                238 0  .021072347
                                239 0   .02034228
                                240 0  .007414316
                                241 0  .008061136
                                242 0  .009181557
                                243 0  .008097126
                                202 0           .
                                203 0           .
                                204 0   .01498101
                                205 0  .013205055
                                206 0  .011536386
                                207 0  .015119858
                                208 0  .015365373
                                209 0   .02042094
                                210 0   .03264662
                                end
                                format %tq datacqtr
                                Last edited by Marco Errico; 22 Aug 2021, 05:27.

                                Comment

                                Working...
                                X