Announcement

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

  • Change in a variable when we have pooled cross-sections

    Hello,

    How can we calculate the change in a variable when its values for two consecutive years are in the same column?

  • #2
    Data example using -dataex-, please!

    Comment


    • #3
      The basic technique is found in
      Code:
      help subscripting

      Comment


      • #4
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str7 year float(raw_edu_1 raw_atten_1 raw_cm_1 raw_nutri_1 raw_elec_1 raw_toilet_1 raw_water_1 raw_house_1 raw_fuel_1 raw_asset_1)
        "2005-06" 24.96722 21.267174 4.801186 57.32859 32.911533 70.91317  21.61364 55.87532 74.326126  46.84115
        "2015-16" 13.86739  6.396226  2.68655 37.59741 12.152462 51.96471 14.595618 45.64145  58.47132 13.967098
        end
        I want to plot all these variables in one graph. I want the 2005-06 values on the x-axis and changes between 2005-06 and 2015-16 on the y-axis. How can I do this?

        Comment


        • #5
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str7 year float(raw_edu_1 raw_atten_1 raw_cm_1 raw_nutri_1 raw_elec_1 raw_toilet_1 raw_water_1 raw_house_1 raw_fuel_1 raw_asset_1)
          "2005-06" 24.96722 21.267174 4.801186 57.32859 32.911533 70.91317  21.61364 55.87532 74.326126  46.84115
          "2015-16" 13.86739  6.396226  2.68655 37.59741 12.152462 51.96471 14.595618 45.64145  58.47132 13.967098
          end
          rename (*_1) (*)
          reshape long raw_, i(year) j(var) string
          rename raw_ value
          replace year = substr(year,1,4)
          reshape wide value, i(var) j(year) string
          generate change = value2015-value2005
          list, clean abbreviate(12)
          scatter change value2005, mlabel(var)
          Code:
          . list, clean abbreviate(12)
          
                    var   value2005   value2015      change  
            1.    asset    46.84115     13.9671   -32.87405  
            2.    atten    21.26717    6.396226   -14.87095  
            3.       cm    4.801186     2.68655   -2.114636  
            4.      edu    24.96722    13.86739   -11.09983  
            5.     elec    32.91153    12.15246   -20.75907  
            6.     fuel    74.32613    58.47132    -15.8548  
            7.    house    55.87532    45.64145   -10.23387  
            8.    nutri    57.32859    37.59741   -19.73118  
            9.   toilet    70.91317    51.96471   -18.94846  
           10.    water    21.61364    14.59562   -7.018022
          Click image for larger version

Name:	Graph2.png
Views:	1
Size:	130.6 KB
ID:	1684900

          Last edited by William Lisowski; 09 Oct 2022, 12:17.

          Comment


          • #6
            Thank you, William.

            Comment


            • #7
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input str7 year byte region_01 double(cen_edu_1_1 cen_atten_1_1 cen_cm_1_1 cen_nutri_1_1 cen_elec_1_1 cen_toilet_1_1 cen_water_1_1 cen_house_1_1 cen_fuel_1_1 cen_asset_1_1)
              "2005-06"  2 24.010227203368558  19.77352905273437  4.518248558044437   44.3099594116212 29.058435440062848  50.42295455933188 16.592025756836158  44.89807891845704  52.89175796508791 37.571495056152436
              "2015-16"  2 11.672297477722166  5.535396099090581 2.2285153865814205 21.213560104370114  8.642709732055662 24.621696472167965  6.227723598480224 23.639839172363278  26.15218925476076   9.54097843170167
              "2005-06"  3 24.010227203369276 19.773529052734535  4.518248558044445 44.309959411620994  29.05843544006334 50.422954559325916 16.592025756835874  44.89807891845705 52.891757965087805 37.571495056151974
              "2015-16"  3 11.672297477722164  5.535396099090571   2.22851538658142  21.21356010437011  8.642709732055662 24.621696472167972  6.227723598480224 23.639839172363274 26.152189254760682  9.540978431701662
              "2005-06"  4 24.010227203369137 19.773529052734276  4.518248558044545 44.309959411620405 29.058435440063754  50.42295455932618 16.592025756836055 44.898078918457045 52.891757965089845  37.57149505615164
              "2015-16"  4 11.672297477722191   5.53539609909058 2.2285153865814227  21.21356010437013  8.642709732055666 24.621696472168008  6.227723598480235 23.639839172363285 26.152189254760785  9.540978431701683
              "2005-06"  5 24.010227203365275 19.773529052734396  4.518248558044353 44.309959411620426 29.058435440063263 50.422954559326165  16.59202575683594 44.898078918454935  52.89175796508034  37.57149505615153
              "2015-16"  5 11.672297477722173  5.535396099090583  2.228515386581422  21.21356010437023   8.64270973205567  24.62169647216807  6.227723598480231 23.639839172363292 26.152189254760817  9.540978431701712
              "2005-06"  7 24.010227203368803 19.773529052734784  4.518248558044435 44.309959411621136 29.058435440062627  50.42295455932668 16.592025756835543  44.89807891845774  52.89175796508788  37.57149505615303
              "2015-16"  7 11.672297477722175   5.53539609909058 2.2285153865814213 21.213560104370167  8.642709732055666 24.621696472167965  6.227723598480228 23.639839172363327 26.152189254760785  9.540978431701689
              "2005-06" 10   24.0102272033679 19.773529052734002  4.518248558044561  44.30995941162114 29.058435440063406  50.42295455932632  16.59202575683594 44.898078918456164  52.89175796508774 37.571495056151356
              "2015-16" 10  11.67229747772219  5.535396099090577 2.2285153865814227  21.21356010437012  8.642709732055671 24.621696472167972  6.227723598480224 23.639839172363278 26.152189254760753  9.540978431701662
              "2005-06" 11 24.010227203369414 19.773529052735626  4.518248558044521  44.30995941161827 29.058435440063494   50.4229545593263 16.592025756835465 44.898078918448256 52.891757965087905  37.57149505615164
              "2015-16" 11 11.672297477722166  5.535396099090577  2.228515386581419 21.213560104370103  8.642709732055662 24.621696472167972 6.2277235984802255 23.639839172363285  26.15218925476074  9.540978431701662
              "2005-06" 12  24.01022720336904 19.773529052734347  4.518248558044542  44.30995941162389  29.05843544006345  50.42295455932615  16.59202575683579  44.89807891845708  52.89175796508769  37.57149505615317
              "2015-16" 12 11.672297477722159  5.535396099090578  2.228515386581422 21.213560104370135  8.642709732055662  24.62169647216796  6.227723598480229 23.639839172363295  26.15218925476075  9.540978431701662
              "2005-06" 13 24.010227203370512 19.773529052735928  4.518248558044325   44.3099594116218 29.058435440064592  50.42295455932679 16.592025756836083   44.8980789184563  52.89175796508784  37.57149505615146
              "2015-16" 13 11.672297477722163  5.535396099090567 2.2285153865814165 21.213560104370114  8.642709732055662 24.621696472167944 6.2277235984802255 23.639839172363246  26.15218925476071  9.540978431701658
              "2005-06" 14 24.010227203369222  19.77352905273426 4.5182485580444265   44.3099594116219 29.058435440062432 50.422954559323344 16.592025756836367 44.898078918457195 52.891757965085766  37.57149505615215
              "2015-16" 14 11.672297477722175   5.53539609909058 2.2285153865814205  21.21356010437012  8.642709732055662 24.621696472167972  6.227723598480236 23.639839172363338 26.152189254760785  9.540978431701662
              "2005-06" 15  24.01022720336882 19.773529052734002  4.518248558044567  44.30995941162191  29.05843544006223  50.42295455932633 16.592025756835394  44.89807891845686 52.891757965087926  37.57149505615157
              "2015-16" 15  11.67229747772215  5.535396099090579 2.2285153865814227 21.213560104370156   8.64270973205567  24.62169647216798  6.227723598480227 23.639839172363317 26.152189254760746  9.540978431701682
              "2005-06" 16  24.01022720336892 19.773529052734112 4.5182485580444185  44.30995941162119  29.05843544006403 50.422954559327756 16.592025756836016 44.898078918456676  52.89175796508829  37.57149505615014
              "2015-16" 16 11.672297477722166  5.535396099090573 2.2285153865814205 21.213560104370103  8.642709732055662 24.621696472167955  6.227723598480213 23.639839172363267 26.152189254760728  9.540978431701667
              "2005-06" 17  24.01022720336946 19.773529052734492  4.518248558044303  44.30995941162366  29.05843544006323   50.4229545593286 16.592025756836048 44.898078918456854  52.89175796509008  37.57149505615139
              "2015-16" 17 11.672297477722166  5.535396099090577 2.2285153865814213 21.213560104370124   8.64270973205567  24.62169647216798  6.227723598480222 23.639839172363285  26.15218925476074  9.540978431701657
              "2005-06" 19 24.010227203368988  19.77352905273439  4.518248558044246 44.309959411621065 29.058435440062865 50.422954559324765 16.592025756835874  44.89807891845693  52.89175796509198  37.57149505615225
              "2015-16" 19 11.672297477722159  5.535396099090577 2.2285153865814182  21.21356010437011   8.64270973205566  24.62169647216791 6.2277235984802255   23.6398391723632  26.15218925476074  9.540978431701657
              "2005-06" 20  24.01022720336911 19.773529052735068  4.518248558044397  44.30995941162085 29.058435440064933  50.42295455932591 16.592025756835778  44.89807891845797  52.89175796508782 37.571495056152045
              "2015-16" 20 11.672297477722166  5.535396099090579 2.2285153865814276 21.213560104370156  8.642709732055687 24.621696472167972 6.2277235984802255 23.639839172363292  26.15218925476078  9.540978431701682
              "2005-06" 21 24.010227203369155 19.773529052734307  4.518248558044338 44.309959411619154 29.058435440062514  50.42295455932785 16.592025756835913  44.89807891845763  52.89175796508152  37.57149505615295
              "2015-16" 21  11.67229747772217  5.535396099090575 2.2285153865814205 21.213560104370096  8.642709732055677 24.621696472167972  6.227723598480223 23.639839172363278 26.152189254760746  9.540978431701658
              "2005-06" 22 24.010227203369283  19.77352905273494  4.518248558044445  44.30995941162109  29.05843544006336  50.42295455932721  16.59202575683595  44.89807891845705  52.89175796508815  37.57149505615095
              "2015-16" 22 11.672297477722154  5.535396099090566 2.2285153865814165 21.213560104370128  8.642709732055666 24.621696472167866  6.227723598480222 23.639839172363175 26.152189254760735  9.540978431701593
              "2005-06" 23  24.01022720336967 19.773529052734357   4.51824855804439  44.30995941162117 29.058435440063448  50.42295455932518  16.59202575683618  44.89807891845704  52.89175796508757 37.571495056152436
              "2015-16" 23  11.67229747772217   5.53539609909057 2.2285153865814205 21.213560104370107   8.64270973205566 24.621696472167972  6.227723598480224 23.639839172363278  26.15218925476074  9.540978431701657
              "2005-06" 24 24.010227203368174 19.773529052734382  4.518248558044427  44.30995941162315  29.05843544006269  50.42295455932562  16.59202575683561 44.898078918457166  52.89175796508788   37.5714950561531
              "2015-16" 24 11.672297477722182  5.535396099090578 2.2285153865814213  21.21356010437012  8.642709732055668    24.621696472168  6.227723598480227 23.639839172363285 26.152189254760767  9.540978431701678
              "2005-06" 25 24.010227203368792 19.773529052734474  4.518248558044461  44.30995941162133 29.058435440063203  50.42295455932879  16.59202575683594  44.89807891845708  52.89175796508554  37.57149505615236
              "2015-16" 25 11.672297477722166  5.535396099090581  2.228515386581423 21.213560104370114  8.642709732055673 24.621696472168015  6.227723598480228  23.63983917236329  26.15218925476079  9.540978431701662
              "2005-06" 26 24.010227203368846 19.773529052734446 4.5182485580444345  44.30995941161898 29.058435440062546  50.42295455932842 16.592025756835913  44.89807891845707 52.891757965089624  37.57149505615239
              "2015-16" 26 11.672297477722166  5.535396099090575 2.2285153865814156 21.213560104370078  8.642709732055662 24.621696472167965 6.2277235984802255 23.639839172363278 26.152189254760703  9.540978431701655
              "2005-06" 28  24.01022720336906  19.77352905273569   4.51824855804432  44.30995941161875 29.058435440063498  50.42295455932678  16.59202575683633  44.89807891845644  52.89175796508547  37.57149505615229
              "2015-16" 28 11.672297477722159  5.535396099090575  2.228515386581418  21.21356010437011  8.642709732055666  24.62169647216791  6.227723598480223 23.639839172363274 26.152189254760682   9.54097843170165
              "2005-06" 29  24.01022720337026  19.77352905273322  4.518248558044432 44.309959411623026 29.058435440064223  50.42295455932564 16.592025756834644  44.89807891845653  52.89175796508963 37.571495056151726
              "2015-16" 29  11.67229747772218  5.535396099090575 2.2285153865814213  21.21356010437012   8.64270973205567 24.621696472167972  6.227723598480224 23.639839172363278 26.152189254760735  9.540978431701678
              "2005-06" 30 24.010227203369016  19.77352905273381 4.5182485580444345  44.30995941162101  29.05843544006501 50.422954559326165  16.59202575683589  44.89807891845579  52.89175796508788 37.571495056152045
              "2015-16" 30 11.672297477722195  5.535396099090581 2.2285153865814236 21.213560104370135    8.6427097320557 24.621696472168033  6.227723598480238 23.639839172363335  26.15218925476074  9.540978431701669
              "2005-06" 31 24.010227203369197 19.773529052734634  4.518248558044149  44.30995941162109 29.058435440062738  50.42295455932652  16.59202575683625 44.898078918457394  52.89175796508943   37.5714950561519
              "2015-16" 31  11.67229747772217  5.535396099090575 2.2285153865814205 21.213560104370114  8.642709732055662 24.621696472167983  6.227723598480224 23.639839172363278  26.15218925476074  9.540978431701662
              "2005-06" 32  24.01022720336933  19.77352905273416  4.518248558044496  44.30995941162109 29.058435440063487  50.42295455932607  16.59202575683587  44.89807891845672  52.89175796508824 37.571495056152735
              "2015-16" 32 11.672297477722177 5.5353960990905815 2.2285153865814205 21.213560104370135  8.642709732055675 24.621696472167987  6.227723598480226 23.639839172363278 26.152189254760728   9.54097843170167
              "2005-06" 33 24.010227203364526 19.773529052728392  4.518248558044048  44.30995941161781  29.05843544006323  50.42295455932397 16.592025756834165  44.89807891845456 52.891757965096275  37.57149505615627
              "2015-16" 33  11.67229747772219 5.5353960990905895 2.2285153865814213 21.213560104370174  8.642709732055693 24.621696472167983  6.227723598480234 23.639839172363295 26.152189254760888  9.540978431701758
              "2005-06" 34 24.010227203369144  19.77352905273478 4.5182485580444425  44.30995941162132  29.05843544006238  50.42295455932638  16.59202575683534 44.898078918457706 52.891757965088075  37.57149505615236
              "2015-16" 34 11.672297477722166  5.535396099090572 2.2285153865814182   21.2135601043701  8.642709732055668 24.621696472167987  6.227723598480224 23.639839172363263  26.15218925476076  9.540978431701662
              "2005-06" 35 24.010227203368395 19.773529052734357  4.518248558044482 44.309959411620774 29.058435440065452  50.42295455933073  16.59202575683594 44.898078918452015   52.8917579650879  37.57149505615194
              "2015-16" 35 11.672297477722166  5.535396099090575  2.228515386581422 21.213560104370114  8.642709732055666  24.62169647216803  6.227723598480221 23.639839172363278 26.152189254760746  9.540978431701664
              "2015-16"  .  11.67229747772217  5.535396099090575 2.2285153865814205 21.213560104370107  8.642709732055666 24.621696472167976 6.2277235984802255 23.639839172363278  26.15218925476075  9.540978431701662
              end
              label values region_01 reg
              label def reg 2 "Andhra Pradesh", modify
              label def reg 3 "Arunachal Pradesh", modify
              label def reg 4 "Assam", modify
              label def reg 5 "Bihar", modify
              label def reg 7 "Chhattisgarh", modify
              label def reg 10 "Goa", modify
              label def reg 11 "Gujarat", modify
              label def reg 12 "Haryana", modify
              label def reg 13 "Himachal Pradesh", modify
              label def reg 14 "Jammu & Kashmir", modify
              label def reg 15 "Jharkhand", modify
              label def reg 16 "Karnataka", modify
              label def reg 17 "Kerala", modify
              label def reg 19 "Madhya Pradesh", modify
              label def reg 20 "Maharashtra", modify
              label def reg 21 "Manipur", modify
              label def reg 22 "Meghalaya", modify
              label def reg 23 "Mizoram", modify
              label def reg 24 "Nagaland", modify
              label def reg 25 "Delhi", modify
              label def reg 26 "Odisha", modify
              label def reg 28 "Punjab", modify
              label def reg 29 "Rajasthan", modify
              label def reg 30 "Sikkim", modify
              label def reg 31 "Tamil Nadu", modify
              label def reg 32 "Tripura", modify
              label def reg 33 "Uttar Pradesh", modify
              label def reg 34 "Uttarakhand", modify
              label def reg 35 "West Bengal", modify
              I'm not able to reshape this data. Can you pls help? I want to look at the change across states.

              Comment


              • #8
                Code:
                drop if region_01==.
                rename (*_1_1) (*)
                reshape long cen_, i(region_01 year) j(var) string
                rename cen_ value
                replace year = substr(year,1,4)
                reshape wide value, i(region_01 var) j(year) string
                generate change = value2015-value2005
                list if region_01==2, clean abbreviate(12)
                list if var=="asset", clean abbreviate(12)
                scatter change value2005, by(region_01) mlabel(var)
                Code:
                . list if region_01==2, clean abbreviate(12)
                
                            region_01      var   value2005   value2015      change  
                  1.   Andhra Pradesh    asset   37.571495   9.5409784   -28.03052  
                  2.   Andhra Pradesh    atten   19.773529   5.5353961   -14.23813  
                  3.   Andhra Pradesh       cm   4.5182486   2.2285154   -2.289733  
                  4.   Andhra Pradesh      edu   24.010227   11.672297   -12.33793  
                  5.   Andhra Pradesh     elec   29.058435   8.6427097   -20.41573  
                  6.   Andhra Pradesh     fuel   52.891758   26.152189   -26.73957  
                  7.   Andhra Pradesh    house   44.898079   23.639839   -21.25824  
                  8.   Andhra Pradesh    nutri   44.309959    21.21356    -23.0964  
                  9.   Andhra Pradesh   toilet   50.422955   24.621696   -25.80126  
                 10.   Andhra Pradesh    water   16.592026   6.2277236    -10.3643  
                
                . list if var=="asset", clean abbreviate(12)
                
                               region_01     var   value2005   value2015      change  
                  1.      Andhra Pradesh   asset   37.571495   9.5409784   -28.03052  
                 11.   Arunachal Pradesh   asset   37.571495   9.5409784   -28.03052  
                 21.               Assam   asset   37.571495   9.5409784   -28.03052  
                 31.               Bihar   asset   37.571495   9.5409784   -28.03052  
                 41.        Chhattisgarh   asset   37.571495   9.5409784   -28.03052  
                 51.                 Goa   asset   37.571495   9.5409784   -28.03052  
                 61.             Gujarat   asset   37.571495   9.5409784   -28.03052  
                 71.             Haryana   asset   37.571495   9.5409784   -28.03052  
                 81.    Himachal Pradesh   asset   37.571495   9.5409784   -28.03052  
                 91.     Jammu & Kashmir   asset   37.571495   9.5409784   -28.03052  
                101.           Jharkhand   asset   37.571495   9.5409784   -28.03052  
                111.           Karnataka   asset   37.571495   9.5409784   -28.03052  
                121.              Kerala   asset   37.571495   9.5409784   -28.03052  
                131.      Madhya Pradesh   asset   37.571495   9.5409784   -28.03052  
                141.         Maharashtra   asset   37.571495   9.5409784   -28.03052  
                151.             Manipur   asset   37.571495   9.5409784   -28.03052  
                161.           Meghalaya   asset   37.571495   9.5409784   -28.03052  
                171.             Mizoram   asset   37.571495   9.5409784   -28.03052  
                181.            Nagaland   asset   37.571495   9.5409784   -28.03052  
                191.               Delhi   asset   37.571495   9.5409784   -28.03052  
                201.              Odisha   asset   37.571495   9.5409784   -28.03052  
                211.              Punjab   asset   37.571495   9.5409784   -28.03052  
                221.           Rajasthan   asset   37.571495   9.5409784   -28.03052  
                231.              Sikkim   asset   37.571495   9.5409784   -28.03052  
                241.          Tamil Nadu   asset   37.571495   9.5409784   -28.03052  
                251.             Tripura   asset   37.571495   9.5409784   -28.03052  
                261.       Uttar Pradesh   asset   37.571495   9.5409784   -28.03052  
                271.         Uttarakhand   asset   37.571495   9.5409784   -28.03052  
                281.         West Bengal   asset   37.571495   9.5409784   -28.03052
                We note that value2005 and value2015 each do not change in different regions.
                Click image for larger version

Name:	Graph3.png
Views:	1
Size:	451.6 KB
ID:	1684909

                Comment


                • #9
                  I understood it now. Thank you, William.

                  Comment


                  • #10
                    Hello,

                    In the very first graph (post 5), If I want different colors for each of the circles, how can I do that?
                    Last edited by Varsha Vaishnav; 17 Oct 2022, 05:16.

                    Comment

                    Working...
                    X