Announcement

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

  • Panel data - xtline scaling issue

    Hello,
    I am running a fixed effects regression for my panel data (xtset regions year). I have 10 regions.
    I want to plot 10 graphs with two lines: each representing my independent variable, and regions on my y axis and year on x axis.
    Unfortuentely, when it type:
    Code:
    xtline r&d gva
    One of my lines is flat due to the fact that value of gva is much smaller than r&d in general. However, when I generate superetly:
    Code:
    xtline  r&d
    xtline gva
    I get nice 10 graphs with visible trends for each variable. Is it possible to put both variables on 1 diagram despite scalling error?

    Thank you very much!

  • #2
    Please give a data example.

    Comment


    • #3
      Nick Cox Of course, here it is:
      Code:
      input long region int year float(access_internet totalrd) long gva
       1 2006 75.5   2085 109887
       1 2007 72.7 2260.5 114161
       1 2008 75.6 2370.5 118349
       1 2009 80.2   2202 115391
       1 2010 80.8   2228 116343
       1 2011 82.1 2135.5 117549
       1 2012 85.6 2124.5 121477
       1 2013 87.7 2416.5 127279
       1 2014   88   2412 134141
       1 2015 92.3 2482.5 139103
       1 2016 91.7 2575.5 144060
       2 2006 58.1    637  75166
       2 2007 73.8    678  78249
       2 2008 68.3    652  80011
       2 2009 71.9  669.5  78992
       2 2010 79.9  738.5  81492
       2 2011 82.1  743.5  83631
       2 2012 86.8    781  86189
       2 2013   88  838.5  89764
       2 2014   87    905  93032
       2 2015 88.7  935.5  96582
       2 2016 90.2  999.5 100141
       3 2006 70.1   1170 287020
       3 2007 69.7   1274 309828
       3 2008 77.1   1339 317266
       3 2009 83.8   1284 310719
       3 2010 86.7   1276 317481
       3 2011   86   1430 329724
       3 2012 90.5 1658.5 345407
       3 2013 94.3   1578 362754
       3 2014 93.8   1820 385331
       3 2015 93.2   1949 397898
       3 2016 95.5 2119.5 422292
       4 2006   63    249  42274
       4 2007 45.6    270  43515
       4 2008 64.3  268.5  44143
       4 2009 71.4  273.5  44309
       4 2010 66.7    271  44457
       4 2011 72.3  245.5  45313
       4 2012 69.5    258  46705
       4 2013 76.9    286  46956
       4 2014 84.7    270  48583
       4 2015 87.5  275.5  50157
       4 2016 95.1  271.5  51419
       5 2006   62   1077 128335
       5 2007 59.6   1280 133878
       5 2008 64.3 1341.5 136146
       5 2009 73.8   1256 136055
       5 2010 77.7   1326 140108
       5 2011 82.9 1397.5 142082
       5 2012 84.9 1177.5 146154
       5 2013 84.4   1216 150385
       5 2014 88.5   1270 156404
       5 2015 88.5 1377.5 163645
       5 2016 93.4   1500 169340
       6 2006 67.2 2091.5 191672
       6 2007 74.7   2182 201410
       6 2008 78.1   2193 212264
       6 2009 81.2   2366 208692
       6 2010 83.4 2389.5 212908
       6 2011 85.2   2799 218763
       6 2012 87.6 2577.5 225381
       6 2013 90.8   2694 234106
       6 2014 90.1 2892.5 246263
       6 2015 93.5   2951 254297
       6 2016 96.3   2981 261546
       7 2006 64.9    755  95187
       7 2007 74.2  755.5  99399
       7 2008 72.1    831 103606
       7 2009 76.9  842.5 102325
       7 2010 75.2    898 104827
       7 2011 84.2  857.5 106738
       7 2012 88.6    863 110561
       7 2013 89.2  916.5 113675
       7 2014 89.2  976.5 119388
       7 2015 90.8    935 121157
       7 2016 92.3  954.5 123759
       8 2006 56.2  225.5  45837
       8 2007 64.5    273  47862
       8 2008   73  240.5  47416
       8 2009 72.6  247.5  47046
       8 2010 83.2    245  48973
       8 2011 73.6  259.5  51131
       8 2012 74.6  264.5  53093
       8 2013   82  324.5  54847
       8 2014 86.6  334.5  56347
       8 2015 88.6    327  57942
       8 2016 88.4  350.5  60550
       9 2006   67    609  93755
       9 2007 71.7  651.5  96529
       9 2008 66.9  606.5  98699
       9 2009 74.4    597  95329
       9 2010 78.3    618  99576
       9 2011 77.5    821 103594
       9 2012 80.2  904.5 106276
       9 2013   83   1027 111832
       9 2014 88.8   1149 117867
       9 2015 88.2   1284 121167
       9 2016 89.8   1355 127653
      10 2006 60.5  420.5  92369
      end
      label values region region
      label def region 1 "East", modify
      label def region 2 "East Midlands", modify
      label def region 3 "London", modify
      label def region 4 "North East", modify
      label def region 5 "North West", modify
      label def region 6 "South East", modify
      label def region 7 "South West", modify
      label def region 8 "Wales", modify
      label def region 9 "West Midlands", modify
      label def region 10 "Yorkshire and The Humber", modify
      The issue is that thrid column is a % access to internet of household in the region in each year

      Comment


      • #4
        One possibility is to scale by a common base, e,g,

        Code:
         foreach v in access_internet totalrd gva {
              egen `v'_2006 = total(`v' * (year == 2006)), by(region)
              gen `v'_scaled = 100 * `v'/`v'_2006
              label var `v'_scaled "`v'" 
         }
        
        . line *scaled year, by(region)

        Comment


        • #5
          Nick Cox thank you very much Sir. Actually, now I have transformed the third column into numbers (not shares), so the values are a bit more similar. The command you have suggested presents the trend really nicely, however it treats all regions as if they were starting at base 100. I would like to show that for instance there was a much smaller internet access to begin with in one compared to other, not that they all started at the same point.
          Is there any chance this could be done?
          Thank you very much for your time

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input long region int year float(totalaccess totalrd) long gva
           1 2006 1480.555   2085 109887
           1 2007  1643.02 2260.5 114161
           1 2008 1633.716 2370.5 118349
           1 2009 1895.928   2202 115391
           1 2010 2004.648   2228 116343
           1 2011  2036.08 2135.5 117549
           1 2012 2136.576 2124.5 121477
           1 2013 2210.917 2416.5 127279
           1 2014  2222.88   2412 134141
           1 2015 2318.576 2482.5 139103
           1 2016 2331.931 2575.5 144060
           2 2006 1012.683    637  75166
           2 2007 1397.034    678  78249
           2 2008 1354.389    652  80011
           2 2009 1427.934  669.5  78992
           2 2010  1534.08  738.5  81492
           2 2011  1592.74  743.5  83631
           2 2012  1675.24    781  86189
           2 2013  1717.76  838.5  89764
           2 2014   1696.5    905  93032
           2 2015 1753.599  935.5  96582
           2 2016 1765.214  999.5 100141
           3 2006 1989.438   1170 287020
           3 2007 2384.437   1274 309828
           3 2008 2342.298   1339 317266
           3 2009 2503.106   1284 310719
           3 2010 2611.404   1276 317481
           3 2011  2590.32   1430 329724
           3 2012  2796.45 1658.5 345407
           3 2013   3017.6   1578 362754
           3 2014 3064.446   1820 385331
           3 2015  3024.34   1949 397898
           3 2016  3174.42 2119.5 422292
           4 2006   646.38    249  42274
           4 2007  591.888    270  43515
           4 2008  852.618  268.5  44143
           4 2009  854.658  273.5  44309
           4 2010 791.7289    271  44457
           4 2011 854.5861  245.5  45313
           4 2012  811.065    258  46705
           4 2013  850.514    286  46956
           4 2014  918.995    270  48583
           4 2015  958.125  275.5  50157
           4 2016   1046.1  271.5  51419
           5 2006  1807.92   1077 128335
           5 2007   1817.8   1280 133878
           5 2008 2003.588 1341.5 136146
           5 2009 2179.314   1256 136055
           5 2010 2357.807   1326 140108
           5 2011 2467.933 1397.5 142082
           5 2012 2522.379 1177.5 146154
           5 2013 2538.752   1216 150385
           5 2014 2673.585   1270 156404
           5 2015 2678.895 1377.5 163645
           5 2016  2778.65   1500 169340
           6 2006 1981.056 2091.5 191672
           6 2007 2108.781   2182 201410
           6 2008 2302.388   2193 212264
           6 2009 2624.384   2366 208692
           6 2010 2751.366 2389.5 212908
           6 2011  2969.22   2799 218763
           6 2012 3108.924 2577.5 225381
           6 2013 3236.112   2694 234106
           6 2014 3250.808 2892.5 246263
           6 2015 3383.765   2951 254297
           6 2016 3530.358   2981 261546
           7 2006 1478.422    755  95187
           7 2007 1846.838  755.5  99399
           7 2008 1858.738    831 103606
           7 2009 1834.065  842.5 102325
           7 2010 1781.488    898 104827
           7 2011 1916.392  857.5 106738
           7 2012 1976.666    863 110561
           7 2013 1968.644  916.5 113675
           7 2014 2022.164  976.5 119388
           7 2015   2111.1    935 121157
           7 2016  2233.66  954.5 123759
           8 2006  690.698  225.5  45837
           8 2007    915.9    273  47862
           8 2008   970.17  240.5  47416
           8 2009  930.732  247.5  47046
           8 2010 1020.864    245  48973
           8 2011  928.832  259.5  51131
           8 2012  939.214  264.5  53093
           8 2013   1037.3  324.5  54847
           8 2014  1108.48  334.5  56347
           8 2015 1162.432    327  57942
           8 2016 1163.344  350.5  60550
           9 2006  1414.37    609  93755
           9 2007 1500.681  651.5  96529
           9 2008 1479.159  606.5  98699
           9 2009  1621.92    597  95329
           9 2010 1742.958    618  99576
           9 2011   1729.8    821 103594
           9 2012 1817.332  904.5 106276
           9 2013  2001.96   1027 111832
           9 2014 2136.528   1149 117867
           9 2015 2102.688   1284 121167
           9 2016 2077.972   1355 127653
          10 2006  1527.02  420.5  92369
          end
          label values region region
          label def region 1 "East", modify
          label def region 2 "East Midlands", modify
          label def region 3 "London", modify
          label def region 4 "North East", modify
          label def region 5 "North West", modify
          label def region 6 "South East", modify
          label def region 7 "South West", modify
          label def region 8 "Wales", modify
          label def region 9 "West Midlands", modify
          label def region 10 "Yorkshire and The Humber", modify

          Comment


          • #6
            There aren't any rules beyond what works. It's not necessarily a choice between only scaled variables and only unscaled variables. But your graph has to be easily understood. I am at a loss to know how you show those magnitudes without some scaling.

            Comment

            Working...
            X