Announcement

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

  • Dealing with "not sorted" r(5)

    Greeting everyone!

    Dear all I have a problem with generating a delta variable,
    HTML Code:
    gen delta_revenues= d.TotalRevenue1
    not sorted
    r(5);
    when I sort
    HTML Code:
    sort TotalRevenue1
    the same issue arises. Therefore, I am requesting you all to kindly guide me in this regard to solve this issue with my data.
    My data is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str52 firmname int yearoficorporation byte(firmauditedbybig4 lossdummy sizeofboard diversityinboard ceoexp) double(sales TotalReceivables Inventory TotalAssets TotalRevenue1 OperatingIncome1 DividendsperShare1)
    2010 "AN Textile Mills Limited"                1982 0 . . . .       .        .        .         .  3196.504   236.022   .8
    2011 "AN Textile Mills Limited"                1982 0 . . . .       .  530.712  768.291   2118.21  4210.345   301.019   .5
    2012 "AN Textile Mills Limited"                1982 0 0 8 1 0       .  603.347  756.323  2143.349   3748.19   202.033    .
    2013 "AN Textile Mills Limited"                1982 0 0 8 1 0       .  595.467  741.008  2404.163  3731.271    228.44    1
    2014 "AN Textile Mills Limited"                1982 0 0 8 1 0 4150.04  682.846  552.908  2238.925  4150.048   168.215    .
    2015 "AN Textile Mills Limited"                1982 0 1 7 1 0 1358.79   200.57  287.085  1424.763  1358.792   -94.942    .
    2016 "AN Textile Mills Limited"                1982 0 1 7 1 0       .  123.319  320.331   1477.12  1466.267  -102.021    .
    2017 "AN Textile Mills Limited"                1982 0 1 7 1 0 1102.93   74.908  182.824  1292.943  1102.932  -106.146    .
    2018 "AN Textile Mills Limited"                1982 0 1 7 1 0 1598.47   92.832    232.2  1363.367  1598.473    21.458    .
    2019 "AN Textile Mills Limited"                1982 0 0 7 1 . 1885.31    85.65  465.935  1638.535   1885.31    89.911   .4
    2010 "Abbot Laboatories (Pakistan) Limited"    1948 0 . 7 0 0       .    652.6   2142.1    5790.4   10149.9    1549.1 4.62
    2011 "Abbot Laboatories (Pakistan) Limited"    1948 0 . 7 0 0       .    830.2   2393.4    7405.3     12947    2281.4    6
    2012 "Abbot Laboatories (Pakistan) Limited"    1948 0 . 7 0 0       .    985.7   2548.4    9329.9   15216.3    2873.3    7
    2013 "Abbot Laboatories (Pakistan) Limited"    1948 0 . 7 0 0       .    796.7   2869.9     11168   17217.3      3481    7
    2014 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 0 0 19692.4    721.4   2943.2   13765.6   19692.4    3847.6  7.8
    2015 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 1 1 21170.4    707.7   3048.8   16488.3   21170.4    4579.7   30
    2016 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 1 1 23387.9     1041   3679.7   17645.2   23387.9    5193.5   40
    2017 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 1 1 26088.2     1120   3605.3   19188.1   26088.2    5485.8   40
    2018 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 1 1 29719.3   1963.2   4607.7   20281.3   29719.3    4281.7   20
    2019 "Abbot Laboatories (Pakistan) Limited"    1948 1 0 7 1 1 30155.9        .        .         .         .         .    .
    2010 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 1 .       .        .        .         .  1249.555   107.134    .
    2011 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 1 .       .        .        .         .  1263.144   157.442    .
    2012 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 0 .       .        .        .         .   581.462   123.242    .
    2013 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 . . .       .        .        .         .  1277.459    -6.551    .
    2014 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 0 . 1057.29        .        .         .  1057.295  -144.429    .
    2015 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 0 . 1763.89        .        .         .   1763.89   -526.58    .
    2016 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 1 7 0 .  430.56        .        .         .   430.564  -349.341    .
    2017 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 0 7 0 .  298.56   11.024  156.655  2858.857   298.566  -126.914    .
    2018 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 1 7 0 .  118.72   13.063  221.934  2803.444   118.723  -264.616    .
    2019 "Abdullah Shah Ghazi Sugar Mills Limited" 1984 0 1 7 0 .  153.11    6.398   236.35  4081.924    153.11  -195.826    .
    2010 "Adam Sugar Mills Limited"                1992 0 0 7 0 0       .  231.209   64.963  1178.781  2138.541   174.917  2.5
    2011 "Adam Sugar Mills Limited"                1992 0 0 7 0 0       .   47.962   297.69  1365.137  2440.693   165.817  2.5
    2012 "Adam Sugar Mills Limited"                1992 0 0 7 0 0       .   51.233 1223.576  2613.935  1535.411   113.152  2.5
    2013 "Adam Sugar Mills Limited"                1992 0 0 7 0 0       .   79.636 1872.697   3577.39  2069.448   230.541  2.5
    2014 "Adam Sugar Mills Limited"                1992 0 0 7 0 0 3174.41  204.059 1395.746  3457.299   3174.41   105.057    .
    2015 "Adam Sugar Mills Limited"                1992 0 1 7 0 . 2451.99  221.672  702.172  2551.805  2589.797    46.421    .
    2016 "Adam Sugar Mills Limited"                1992 0 0 7 0 . 3261.24  216.939  227.252  2270.717  3261.247     240.8  3.5
    2017 "Adam Sugar Mills Limited"                1992 0 1 7 0 . 1849.97   48.374  1959.91  4063.899  1849.979    -9.051    .
    2018 "Adam Sugar Mills Limited"                1992 0 1 7 0 . 3762.79  298.209 1390.254  3735.766  3762.794   -41.839    .
    2019 "Adam Sugar Mills Limited"                1992 0 1 7 0 . 2314.62   82.813 1051.479  6432.592  2314.623   -91.169    .
    2010 "Ados Pakistan Limited"                   1986 0 . . . .       .  128.029    4.918   374.249    535.18    63.669    .
    2011 "Ados Pakistan Limited"                   1986 0 . 7 1 0       .   58.863    5.758   468.109   462.366    18.088    .
    2012 "Ados Pakistan Limited"                   1986 0 . 7 1 0       .  180.357   14.507   453.433    291.31    24.021    .
    2013 "Ados Pakistan Limited"                   1986 0 . 7 1 0       .  467.719    7.712   878.374  1061.079    152.72    .
    2014 "Ados Pakistan Limited"                   1986 0 0 7 1 . 724.179  386.238   19.785   796.485   724.179    24.441    .
    2015 "Ados Pakistan Limited"                   1986 0 0 9 0 . 580.257  294.434    67.99   659.039   580.257    15.975    5
    2016 "Ados Pakistan Limited"                   1986 0 0 9 0 . 613.952  121.075   68.424   475.922   613.952     13.36    .
    2017 "Ados Pakistan Limited"                   1986 0 0 9 0 . 427.291  127.588   58.305   436.168   427.291    -4.515    .
    2018 "Ados Pakistan Limited"                   1986 0 1 9 0 . 107.962   24.264   55.482   292.153   107.962   -47.059    .
    2019 "Ados Pakistan Limited"                   1986 0 1 9 0 .  38.069   13.352   75.311   280.029    38.069   -44.093    .
    2010 "Agriauto Industries Limited"             1981 1 0 7 0 1       .    314.1    677.4    2149.5    3906.5     735.1  4.5
    2011 "Agriauto Industries Limited"             1981 1 0 7 0 1       .    356.1    667.1    2447.4    3980.3     666.5    5
    2012 "Agriauto Industries Limited"             1981 1 0 7 0 1       .      326    759.7    2905.1    4286.7     737.5  7.5
    2013 "Agriauto Industries Limited"             1981 1 0 7 0 1       .    492.3      701    2957.6    3503.6     353.2  5.5
    2014 "Agriauto Industries Limited"             1981 1 0 7 0 1  3158.8    408.6    540.2    3060.4    3158.5     291.5    5
    2015 "Agriauto Industries Limited"             1981 1 0 7 0 1 4923.28    650.4    954.6    3662.9    5635.6     832.8  7.5
    2016 "Agriauto Industries Limited"             1981 1 0 7 0 1 5758.38    625.9     1003    4043.1    7137.1    1020.9 8.75
    2017 "Agriauto Industries Limited"             1981 1 0 7 0 1 5657.54    868.9   1155.9    4697.5    7115.3      1082   10
    2018 "Agriauto Industries Limited"             1981 1 0 7 0 1 6112.98      977   1552.1      5315      8315    1239.1 12.5
    2019 "Agriauto Industries Limited"             1981 1 0 7 1 1 7122.49   1915.3     1725    6140.8   10128.6    1297.4   10
    2010 "Agritech Limited"                        1959 0 . . . .       . 1724.832 1686.867 40943.644 12854.551  2515.552    .
    2011 "Agritech Limited"                        1959 1 0 8 0 0       . 1208.675 2480.984 43757.394  5149.162   915.967    .
    2012 "Agritech Limited"                        1959 1 1 7 0 0       . 1004.366  2774.67 44045.956  5697.064    734.34    .
    2013 "Agritech Limited"                        1959 1 1 8 0 0       .  845.434 2577.159 44239.183  5751.782   501.584    .
    2014 "Agritech Limited"                        1959 1 1 8 0 0 2794.63  958.922 2417.358  49646.47  2794.628 -1907.549    .
    2015 "Agritech Limited"                        1959 1 1 8 0 1 3542.57 1155.323 2681.238 48984.233   3542.57 -1472.408    .
    2016 "Agritech Limited"                        1959 1 1 8 1 0 8238.58 1802.934 2386.724 47904.596  7515.414   447.945    .
    2017 "Agritech Limited"                        1959 1 1 7 0 0 3551.52 1877.297 2475.166 47088.681  3551.519 -1757.005    .
    2018 "Agritech Limited"                        1959 1 1 7 1 . 4533.32 1648.283 2348.015 46209.442  4533.316  -921.359    .
    2019 "Agritech Limited"                        1959 0 1 7 1 1 12174.4        .        .         .         .         .    .
    2010 "Ahmed Hassan Textile Mills Limited"      1989 0 0 7 1 0       .  209.525  662.929  2831.824   3311.02   281.137    .
    2011 "Ahmed Hassan Textile Mills Limited"      1989 0 0 7 1 0       .  378.377  537.102  2698.605  3991.815   409.126 1.25
    2012 "Ahmed Hassan Textile Mills Limited"      1989 0 0 7 1 0       .   260.85  491.722   2551.32  3376.916   289.356 1.25
    2013 "Ahmed Hassan Textile Mills Limited"      1989 1 0 7 1 0       .  255.519   535.42  3282.057  4015.813   256.811  1.5
    2014 "Ahmed Hassan Textile Mills Limited"      1989 0 0 7 1 0 3977.31  388.799  631.864  3634.275   3977.31   182.081    .
    2015 "Ahmed Hassan Textile Mills Limited"      1989 0 1 7 1 0 3248.86   292.46  587.369  3667.439  3248.868    30.607    .
    2016 "Ahmed Hassan Textile Mills Limited"      1989 0 1 7 1 0 3455.55  281.833  692.637  3674.675  3455.552   114.885    .
    2017 "Ahmed Hassan Textile Mills Limited"      1989 0 1 7 1 0 4055.87  403.354  935.359   4116.63  4055.873   111.318    .
    2018 "Ahmed Hassan Textile Mills Limited"      1989 0 0 8 1 0    5179  491.432  921.594  4314.902  5179.001   180.607 1.25
    2019 "Ahmed Hassan Textile Mills Limited"      1989 0 0 8 1 0 7273.99   539.37 1169.501  4759.427  7273.994    315.95 1.25
    2010 "Aisha Steel Mills Limited"               2005 . . . . .       .        .        .         .         .         .    .
    2011 "Aisha Steel Mills Limited"               2005 1 . . . .       .     30.6     92.2    8475.9         .    -107.1    .
    2012 "Aisha Steel Mills Limited"               2005 1 1 8 0 1       .    332.5    626.6   10947.1         .    -155.5    .
    2013 "Aisha Steel Mills Limited"               2005 1 1 8 0 1       .    876.3   2468.5   14350.5    4341.6      -240    .
    2014 "Aisha Steel Mills Limited"               2005 1 1 8 0 1 9259.03   1123.3   3506.3   16280.2      9259      -109    .
    2015 "Aisha Steel Mills Limited"               2005 1 1 9 0 1 9491.75   1160.6   2596.8   15336.9    9491.7      -121    .
    2016 "Aisha Steel Mills Limited"               2005 1 1 9 0 1  9634.3    904.3   2994.3   15352.3    9634.3     805.1    .
    2017 "Aisha Steel Mills Limited"               2005 1 0 9 0 1 14075.9    887.2   3812.3   18183.9   14075.9    1827.1    .
    2018 "Aisha Steel Mills Limited"               2005 1 0 9 1 1 18903.9     1045   4424.3   20425.8   18903.9    2984.3    .
    2019 "Aisha Steel Mills Limited"               2005 1 0 9 1 1 20230.8   2585.2   7299.5   32730.9   20230.8    1445.3    .
    2010 "Akzo Nobel Pakistan Limited"             2011 . . . . .       .        .        .         .         .         .    .
    2011 "Akzo Nobel Pakistan Limited"             2011 . . . . .       . 3937.414  793.475  6641.857   4892.84   551.406    .
    2012 "Akzo Nobel Pakistan Limited"             2011 . . . . .       .   465.21  565.727  7361.965  4764.191   270.835  2.5
    2013 "Akzo Nobel Pakistan Limited"             2011 . . . . .       .  616.648  617.992   4248.63  5265.144   663.485  2.5
    2014 "Akzo Nobel Pakistan Limited"             2011 1 0 7 0 1 4901.79  557.076  378.957  3973.367  4901.791   557.439  2.5
    2015 "Akzo Nobel Pakistan Limited"             2011 1 0 7 0 0 4927.23  498.532  380.232  4215.833  4927.235   651.613  6.5
    2016 "Akzo Nobel Pakistan Limited"             2011 1 0 7 0 1 5690.57  544.016  487.152  5086.936  5136.961   674.894  6.5
    2017 "Akzo Nobel Pakistan Limited"             2011 1 0 7 0 1 5812.74  829.749  612.612  5772.052  5690.577    782.71    7
    2018 "Akzo Nobel Pakistan Limited"             2011 1 0 7 1 1 5611.54  818.916  691.544  5711.194  5812.743   614.171    5
    2019 "Akzo Nobel Pakistan Limited"             2011 1 0 7 1 1       .  992.317  709.888  8415.644  5611.541   696.247    6
    end
    format %ty year
    label values firmauditedbybig4 firmsauditor
    label def firmsauditor 0 "Non-BIG 4", modify
    label def firmsauditor 1 "BIG 4", modify

    Regards
    Sattar Khan
    Last edited by Sattar Khan; 14 Dec 2021, 04:35.

  • #2
    Might be better to provide a dataexample using command
    Code:
    dataex
    My two cents on that is that you are not specifying the panel data (i.e. you need the id dimension variable)
    With a data example we can see better. But
    Code:
    d.
    need an identifier in order to calculate delta

    Comment


    • #3
      As I said, the issue is related that you need an id and specify the panel
      Code:
      egen id= group(firmname)
      xtset id year
      gen delta_revenues= d.TotalRevenue1
      Here there are two things that is better I clarify:
      1. I see you don't have identifiers, therefore I have generated one based on company name. But this is not the cleanest way to do that given that if the company changes even one letter from one year to another, then stata treats it as a different one
      2. I am assuming that you want the delta revenues from one year to another using "year" variable

      Comment


      • #4
        Originally posted by Marco Errico View Post
        As I said, the issue is related that you need an id and specify the panel
        Code:
        egen id= group(firmname)
        xtset id year
        gen delta_revenues= d.TotalRevenue1
        Here there are two things that is better I clarify:
        1. I see you don't have identifiers, therefore I have generated one based on company name. But this is not the cleanest way to do that given that if the company changes even one letter from one year to another, then stata treats it as a different one
        2. I am assuming that you want the delta revenues from one year to another using "year" variable
        Thank You Errico, i didn't set xtset id year. The issue has been resolved now. Thank You again

        Comment

        Working...
        X