Announcement

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

  • How to gen crash risk variable with the following data

    Hi Folks, I have been strongly with my data, trying to figure out how to gen my crash risk varaible through the NCSKEW method. First of all let me explain my data.
    My dataset is observations from two years (2019 and 2020) and in each year, each observation is observe only once. I used the average daily price of the stock market Y to compute the return (log Ri = log P1/p0) of firm X on the stock market Y. in addition, because the RM in the dataset was on yearly frequency, I also converted them on daily freqency by dividing each stock market RM on the number of trading days in each year accordingly, and then the average value was log given (log RM). After that I further convert them (daily frequency) in weekly frequency by using the command "ascol logRi, toweek returns(log) " to convert firm x daily return to weekly return and "ascol logRM, toweek returns(log)" to convert stock market Y daily return to weekly return which created respectivelly the variable week_logRi and week_logRM. However, I failed to gen my crash risk variable and will apreciate your assistance and guidance to solve this issue. following the data and commands used

    bysort ID (Year) : gen t = _n
    xtset ID t
    ascol logRi, toweek returns(log) keep(all)
    ascol logRM, toweek return(log) keep(all)
    bysort ID (t) : gen F1week_logRM = F1.week_logRM
    bysort ID (t) : gen F2week_logRM = F2.week_logRM
    bysort ID (t) : gen L1week_logRM = L1.week_logRM
    bysort ID (t) : gen L2week_logRM = L2.week_logRM
    reg week_logRi F2week_logRM F1week_logRM week_logRM L1week_logRM L2week_logRM
    ID Year Y20 logRi logRM t week_id week_logRi week_id_000 week_logRM F1week_logRM F2week_logRM L1week_logRM L2week_logRM
    1 2019 0 -0.02896 3.046095 1 1960w1 -0.2005 1960w1 5.852192 5.852192
    1 2020 1 -0.17154 2.806097 2 1960w1 -0.2005 1960w1 5.852192 5.852192
    2 2019 0 0.251595 1.111734 1 1960w1 0.189728 1960w1 2.142712 2.142712
    2 2020 1 -0.06187 1.030978 2 1960w1 0.189728 1960w1 2.142712 2.142712
    3 2019 0 -0.07646 0.993631 1 1960w1 -0.07646 1960w1 2.032012 2.032012
    3 2020 1 1.038381 2 1960w1 -0.07646 1960w1 2.032012 2.032012
    4 2019 0 -0.06928 1.974644 1 1960w1 -0.27866 1960w1 3.897344 3.897344
    4 2020 1 -0.20938 1.9227 2 1960w1 -0.27866 1960w1 3.897344 3.897344
    5 2019 0 -0.03636 0.669499 1 1960w1 -0.4125 1960w1 1.284535 1.284535
    5 2020 1 -0.37614 0.615036 2 1960w1 -0.4125 1960w1 1.284535 1.284535
    6 2019 0 0.130941 1.909187 1 1960w1 0.014509 1960w1 3.822878 3.822878
    6 2020 1 -0.11643 1.913692 2 1960w1 0.014509 1960w1 3.822878 3.822878
    7 2019 0 0.100415 -2.73595 1 1960w1 -0.15551 1960w1 -5.56882 -5.56882
    7 2020 1 -0.25593 -2.83286 2 1960w1 -0.15551 1960w1 -5.56882 -5.56882
    8 2019 0 -0.34783 1 1960w1 -0.34684 1960w1 0 0
    8 2020 1 0.000986 2 1960w1 -0.34684 1960w1 0 0
    9 2019 0 -0.03502 0.153687 1 1960w1 -0.02173 1960w1 0.319106 0.319106
    9 2020 1 0.013289 0.165418 2 1960w1 -0.02173 1960w1 0.319106 0.319106
    10 2019 0 -0.17036 3.863509 1 1960w1 -0.61293 1960w1 3.863509 3.863509
    10 2020 1 -0.44256 2 1960w1 -0.61293 1960w1 3.863509 3.863509
    11 2019 0 1 1960w1 0 1960w1 0 0
    11 2020 1 2 1960w1 0 1960w1 0 0
    12 2019 0 1 1960w1 -0.17236 1960w1 0 0
    12 2020 1 -0.17236 2 1960w1 -0.17236 1960w1 0 0
    13 2019 0 1 1960w1 0.015647 1960w1 0 0
    13 2020 1 0.015647 2 1960w1 0.015647 1960w1 0 0
    14 2019 0 -0.14427 1 1960w1 -0.74761 1960w1 0 0
    14 2020 1 -0.60334 2 1960w1 -0.74761 1960w1 0 0
    15 2019 0 -0.06727 1.551518 1 1960w1 -0.08119 1960w1 3.258592 3.258592
    15 2020 1 -0.01392 1.707074 2 1960w1 -0.08119 1960w1 3.258592 3.258592
    16 2019 0 -0.36597 1 1960w1 -0.13355 1960w1 0 0
    16 2020 1 0.232413 2 1960w1 -0.13355 1960w1 0 0
    17 2019 0 0.034605 1.834126 1 1960w1 -0.26272 1960w1 3.674969 3.674969
    17 2020 1 -0.29733 1.840843 2 1960w1 -0.26272 1960w1 3.674969 3.674969
    18 2019 0 0.053063 1 1960w1 0 1960w1 0.053063 0.053063
    18 2020 1 2 1960w1 0 1960w1 0.053063 0.053063
    19 2019 0 -0.0951 1.429542 1 1960w1 -0.00121 1960w1 2.858731 2.858731
    19 2020 1 0.093894 1.429189 2 1960w1 -0.00121 1960w1 2.858731 2.858731
    20 2019 0 -0.05411 1.666591 1 1960w1 -0.09873 1960w1 3.342617 3.342617
    20 2020 1 -0.04461 1.676027 2 1960w1 -0.09873 1960w1 3.342617 3.342617
    21 2019 0 -0.03242 1.798079 1 1960w1 0.017638 1960w1 3.714544 3.714544
    21 2020 1 0.050062 1.916466 2 1960w1 0.017638 1960w1 3.714544 3.714544
    22 2019 0 -0.23705 1.405388 1 1960w1 -0.39493 1960w1 2.916101 2.916101
    22 2020 1 -0.15788 1.510713 2 1960w1 -0.39493 1960w1 2.916101 2.916101
    23 2019 0 -0.07207 1.273898 1 1960w1 0.018077 1960w1 2.690487 2.690487
    23 2020 1 0.090148 1.41659 2 1960w1 0.018077 1960w1 2.690487 2.690487
    24 2019 0 -0.10436 0.584779 1 1960w1 -0.26396 1960w1 1.226296 1.226296
    24 2020 1 -0.15961 0.641517 2 1960w1 -0.26396 1960w1 1.226296 1.226296
    25 2019 0 -0.07256 2.178476 1 1960w1 0.009208 1960w1 4.40623 4.40623
    25 2020 1 0.081773 2.227754 2 1960w1 0.009208 1960w1 4.40623 4.40623
    26 2019 0 -0.05351 1.411919 1 1960w1 -0.17105 1960w1 2.981727 2.981727
    26 2020 1 -0.11754 1.569808 2 1960w1 -0.17105 1960w1 2.981727 2.981727
    27 2019 0 -0.03566 0.853855 1 1960w1 -0.05772 1960w1 1.724649 1.724649
    27 2020 1 -0.02206 0.870794 2 1960w1 -0.05772 1960w1 1.724649 1.724649
    28 2019 0 -0.14888 0.951027 1 1960w1 -0.0007 1960w1 2.014982 2.014982
    28 2020 1 0.148187 1.063955 2 1960w1 -0.0007 1960w1 2.014982 2.014982
    29 2019 0 1 1960w1 -0.32587 1960w1 0 0
    29 2020 1 -0.32587 2 1960w1 -0.32587 1960w1 0 0
    30 2019 0 0.036449 1.605263 1 1960w1 0.016657 1960w1 3.265251 3.265251
    30 2020 1 -0.01979 1.659988 2 1960w1 0.016657 1960w1 3.265251 3.265251
    31 2019 0 -0.16076 1.69537 1 1960w1 -0.33512 1960w1 3.44795 3.44795
    31 2020 1 -0.17436 1.75258 2 1960w1 -0.33512 1960w1 3.44795 3.44795
    32 2019 0 0.01628 1.281816 1 1960w1 -0.07339 1960w1 2.530492 2.530492
    32 2020 1 -0.08967 1.248676 2 1960w1 -0.07339 1960w1 2.530492 2.530492
    33 2019 0 -0.04439 1.096927 1 1960w1 -0.00954 1960w1 2.252034 2.252034
    33 2020 1 0.034848 1.155107 2 1960w1 -0.00954 1960w1 2.252034 2.252034
    34 2019 0 -0.03665 0.848883 1 1960w1 -0.0021 1960w1 2.623766 2.623765
    34 2020 1 0.034556 1.774883 2 1960w1 -0.0021 1960w1 2.623766 2.623765
    35 2019 0 1.150303 1 1960w1 0 1960w1 2.202803 2.202803
    35 2020 1 1.0525 2 1960w1 0 1960w1 2.202803 2.202803
    36 2019 0 0.014351 -0.20958 1 1960w1 0.060485 1960w1 -0.33369 -0.33369
    36 2020 1 0.046134 -0.12411 2 1960w1 0.060485 1960w1 -0.33369 -0.33369
    37 2019 0 -0.02256 1.695262 1 1960w1 0.017436 1960w1 3.47615 3.47615
    37 2020 1 0.039993 1.780888 2 1960w1 0.017436 1960w1 3.47615 3.47615
    38 2019 0 0.007327 0.811223 1 1960w1 -0.09481 1960w1 1.58679 1.58679
    38 2020 1 -0.10214 0.775567 2 1960w1 -0.09481 1960w1 1.58679 1.58679
    39 2019 0 -0.00394 1.309303 1 1960w1 -0.01806 1960w1 2.612517 2.612517
    39 2020 1 -0.01412 1.303214 2 1960w1 -0.01806 1960w1 2.612517 2.612517
    40 2019 0 -0.16571 0.862725 1 1960w1 -0.15354 1960w1 1.753726 1.753726
    40 2020 1 0.012165 0.891001 2 1960w1 -0.15354 1960w1 1.753726 1.753726
    41 2019 0 1 1960w1 0 1960w1 0 0
    41 2020 1 2 1960w1 0 1960w1 0 0
    42 2019 0 -0.02988 0.569516 1 1960w1 -0.11152 1960w1 1.08126 1.08126
    42 2020 1 -0.08163 0.511744 2 1960w1 -0.11152 1960w1 1.08126 1.08126
    43 2019 0 0.890904 1 1960w1 -0.63607 1960w1 1.673091 1.673091
    43 2020 1 -0.63607 0.782187 2 1960w1 -0.63607 1960w1 1.673091 1.673091
    44 2019 0 -0.12567 1 1960w1 -0.25644 1960w1 0 0
    44 2020 1 -0.13077 2 1960w1 -0.25644 1960w1 0 0
    45 2019 0 -0.0438 1 1960w1 -0.36448 1960w1 0 0
    45 2020 1 -0.32068 2 1960w1 -0.36448 1960w1 0 0
    46 2019 0 -0.03243 0.573319 1 1960w1 -0.2419 1960w1 1.072559 1.072559
    46 2020 1 -0.20948 0.49924 2 1960w1 -0.2419 1960w1 1.072559 1.072559
    47 2019 0 -0.0997 2.662321 1 1960w1 -0.10399 1960w1 3.430219 3.430219
    47 2020 1 -0.00428 0.767898 2 1960w1 -0.10399 1960w1 3.430219 3.430219
    48 2019 0 -2.69511 1.482069 1 1960w1 -0.23737 1960w1 2.919942 2.919942
    48 2020 1 2.457734 1.437874 2 1960w1 -0.23737 1960w1 2.919942 2.919942
    49 2019 0 0.017919 1.694423 1 1960w1 -0.09976 1960w1 3.349076 3.349077
    49 2020 1 -0.11767 1.654653 2 1960w1 -0.09976 1960w1 3.349076 3.349077
    50 2019 0 -0.33638 -0.19415 1 1960w1 -0.26936 1960w1 -0.43307 -0.43307
    50 2020 1 0.067019 -0.23893 2 1960w1 -0.26936 1960w1 -0.43307 -0.43307
    51 2019 0 -0.02175 0.777007 1 1960w1 -0.09694 1960w1 1.546572 1.546571
    51 2020 1 -0.0752 0.769564 2 1960w1 -0.09694 1960w1 1.546572 1.546571
    52 2019 0 -0.05451 1.19469 1 1960w1 -0.06952 1960w1 2.359687 2.359687
    52 2020 1 -0.01502 1.164997 2 1960w1 -0.06952 1960w1 2.359687 2.359687
    53 2019 0 0.784658 1 1960w1 -0.07667 1960w1 1.540431 1.540431
    53 2020 1 -0.07667 0.755773 2 1960w1 -0.07667 1960w1 1.540431 1.540431
    54 2019 0 -0.02811 0.69128 1 1960w1 -0.13594 1960w1 1.336182 1.336182
    54 2020 1 -0.10783 0.644902 2 1960w1 -0.13594 1960w1 1.336182 1.336182
    55 2019 0 -0.1256 -0.57229 1 1960w1 -0.23417 1960w1 -1.21026 -1.21026
    55 2020 1 -0.10858 -0.63797 2 1960w1 -0.23417 1960w1 -1.21026 -1.21026
    56 2019 0 -0.03818 0.352032 1 1960w1 -0.13834 1960w1 0.715629 0.715629
    56 2020 1 -0.10017 0.363597 2 1960w1 -0.13834 1960w1 0.715629 0.715629
    57 2019 0 -0.06428 1.045474 1 1960w1 -0.12872 1960w1 2.042343 2.042343
    57 2020 1 -0.06444 0.996869 2 1960w1 -0.12872 1960w1 2.042343 2.042343
    58 2019 0 -0.02289 1.677334 1 1960w1 -0.15646 1960w1 3.562448 3.562448
    58 2020 1 -0.13357 1.885115 2 1960w1 -0.15646 1960w1 3.562448 3.562448
    59 2019 0 1 1960w1 0.508187 1960w1 0 0
    59 2020 1 0.508187 2 1960w1 0.508187 1960w1 0 0
    60 2019 0 0.068563 2.376304 1 1960w1 0.280565 1960w1 4.766339 4.766338
    60 2020 1 0.212002 2.390035 2 1960w1 0.280565 1960w1 4.766339 4.766338
    61 2019 0 -0.10004 1.935262 1 1960w1 -0.19767 1960w1 3.841573 3.841573
    61 2020 1 -0.09763 1.906311 2 1960w1 -0.19767 1960w1 3.841573 3.841573
    62 2019 0 -0.32987 1 1960w1 -0.52483 1960w1 0 0
    62 2020 1 -0.19496 2 1960w1 -0.52483 1960w1 0 0
    63 2019 0 -0.02207 1.221484 1 1960w1 -0.09651 1960w1 2.380039 2.380039
    63 2020 1 -0.07444 1.158555 2 1960w1 -0.09651 1960w1 2.380039 2.380039
    64 2019 0 1.420752 0.416808 1 1960w1 1.440192 1960w1 0.836744 0.836744
    64 2020 1 0.01944 0.419936 2 1960w1 1.440192 1960w1 0.836744 0.836744
    65 2019 0 -0.12392 1 1960w1 -0.12639 1960w1 0 0
    65 2020 1 -0.00247 2 1960w1 -0.12639 1960w1 0 0
    67 2019 0 -0.56644 1 1960w1 -0.70323 1960w1 0 0
    67 2020 1 -0.13679 2 1960w1 -0.70323 1960w1 0 0
    68 2019 0 1.22227 1 1960w1 1.20277 1960w1 0 0
    68 2020 1 -0.0195 2 1960w1 1.20277 1960w1 0 0
    69 2019 0 -0.9622 1.198612 1 1960w1 -1.06043 1960w1 2.364008 2.364007
    69 2020 1 -0.09823 1.165395 2 1960w1 -1.06043 1960w1 2.364008 2.364007
    70 2019 0 -1.10019 -0.16799 1 1960w1 -1.26271 1960w1 -0.37144 -0.37144
    70 2020 1 -0.16252 -0.20345 2 1960w1 -1.26271 1960w1 -0.37144 -0.37144
    71 2019 0 0.719844 1 1960w1 -0.06068 1960w1 1.407425 1.407425
    71 2020 1 -0.06068 0.687582 2 1960w1 -0.06068 1960w1 1.407425 1.407425
    72 2019 0 1.345018 0.151593 1 1960w1 1.321847 1960w1 0.379806 0.379806
    72 2020 1 -0.02317 0.228213 2 1960w1 1.321847 1960w1 0.379806 0.379806
    73 2019 0 0.284056 1 1960w1 0.23384 1960w1 0 0
    73 2020 1 -0.05022 2 1960w1 0.23384 1960w1 0 0
    74 2019 0 -0.23741 0.305979 1 1960w1 -0.29438 1960w1 0.560939 0.560939
    74 2020 1 -0.05698 0.254959 2 1960w1 -0.29438 1960w1 0.560939 0.560939
    75 2019 0 -0.03736 1.100316 1 1960w1 0.038737 1960w1 2.262963 2.262963
    75 2020 1 0.076096 1.162647 2 1960w1 0.038737 1960w1 2.262963 2.262963
    76 2019 0 1 1960w1 -0.14619 1960w1 0 0
    76 2020 1 -0.14619 2 1960w1 -0.14619 1960w1 0 0
    77 2019 0 -0.14398 -0.02917 1 1960w1 -0.17088 1960w1 -0.16382 -0.16382
    77 2020 1 -0.0269 -0.13465 2 1960w1 -0.17088 1960w1 -0.16382 -0.16382
    78 2019 0 -0.24077 1.52927 1 1960w1 0.326472 1960w1 3.072067 3.072067
    78 2020 1 0.567245 1.542797 2 1960w1 0.326472 1960w1 3.072067 3.072067
    79 2019 0 -0.07339 1.71054 1 1960w1 -0.16254 1960w1 3.435628 3.435628
    79 2020 1 -0.08915 1.725087 2 1960w1 -0.16254 1960w1 3.435628 3.435628
    80 2019 0 -0.02179 0.941677 1 1960w1 -0.08118 1960w1 1.757337 1.757336
    80 2020 1 -0.05939 0.815659 2 1960w1 -0.08118 1960w1 1.757337 1.757336
    81 2019 0 -0.07251 3.188966 1 1960w1 -0.17205 1960w1 6.94702 6.947021
    81 2020 1 -0.09954 3.758054 2 1960w1 -0.17205 1960w1 6.94702 6.947021
    82 2019 0 -0.09247 0.700657 1 1960w1 0.16774 1960w1 1.396135 1.396135
    82 2020 1 0.260209 0.695478 2 1960w1 0.16774 1960w1 1.396135 1.396135
    83 2019 0 -0.00504 1.753999 1 1960w1 -0.03722 1960w1 3.398304 3.398304
    83 2020 1 -0.03218 1.644305 2 1960w1 -0.03722 1960w1 3.398304 3.398304
    84 2019 0 -0.07253 1.459911 1 1960w1 -0.12249 1960w1 2.912204 2.912204
    84 2020 1 -0.04996 1.452293 2 1960w1 -0.12249 1960w1 2.912204 2.912204
    85 2019 0 -0.16153 2.367723 1 1960w1 -0.44342 1960w1 4.725855 4.725855
    85 2020 1 -0.28189 2.358132 2 1960w1 -0.44342 1960w1 4.725855 4.725855
    86 2019 0 1 1960w1 -0.04504 1960w1 0 0
    86 2020 1 -0.04504 2 1960w1 -0.04504 1960w1 0 0
    89 2019 0 -0.05151 0.910347 1 1960w1 -0.16092 1960w1 1.749318 1.749318
    89 2020 1 -0.10941 0.838971 2 1960w1 -0.16092 1960w1 1.749318 1.749318
    90 2019 0 0.054172 1 1960w1 0.030072 1960w1 0 0
    90 2020 1 -0.0241 2 1960w1 0.030072 1960w1 0 0
    reg week_logRi F2week_logRM F1week_logRM week_logRM L1week_logRM L2week_logRM
    no observations
    r(2000);

    predict double e, residuals
    last estimates not found
    r(301);

    Many thanks in advance.
    0
    i will be so thankful to recieve your assistance and guidance .
    0%
    0
    Thank you all.
    0%
    0
    Last edited by Bienmali Kombate; 17 Sep 2022, 04:46.

  • #2
    In any Stata estimation command, any observation that contains a missing value on any variable in the command is omitted. The variables f2week_logrm and l2week_logrm have exclusively missing values. Therefore, every observation in the data set is excluded from the regression and you have no observations for -regress- to work with. This is what accounts for the "no observations" error message. The subsequent "last estimates not found" is simply a restatement of the fact that regression itself failed, so it is not possible to carry out the -predict- command.

    Either something is wrong with your data set, and the values of these two variables were never created or were somehow dropped, and you must go back and fix your data set before you can proceed. Or, if those variables are really supposed to be missing* (which would be odd? Why have them at all in that case?) then you need to remove them from the regression command.


    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 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.

    *Added: because the two problematic variables begin with f2 and l2, and you also have l1, l2, and f1 variables in your data, I am guessing that these variables are intended to be lags and leads of the variable logrm. It is also true in the example data that for each id there are only two observations, one for 2019, and one for 2020. When there are only two observations per id, the second lags and leads will never exist--you can only go one time period forward or backward and remain in the data. Only the first lags and leads exist. If I am on the right track here, you need more years of data in your data set, or, if data outside of 2019 and 2020 is not obtainable, you have to omit 2nd and higher order lags and leads from your analyses (and, in this case, don't bother creating variables for them that cannot contain any information.)

    Also, if these are intended to be lags and leads, rather than creating your own variables for them, which is error prone, it is safer to use Stata's time series operators. Read -help tsvarlist- for details.
    Last edited by Clyde Schechter; 17 Sep 2022, 09:46.

    Comment


    • #3
      Dear Schechter, many thanks for your comment and suggestions, and sorry for not following the appropiated way of posting. However, I hope you still can help with the posted data, otherwise, I can edit the post accordingly.
      Yes, you are right, the variables with F1 and F2 are leads and L1, L2 are lags respectively for the weekly frenquecy return.
      The data of 2018 and 2021 exist, but due to the specific context of our current study, the scope of our sample is limited to the year 2019 and 2020, But I supposed to added that I also run the reg command excluding the two variables (F2 and L2) and the results was the same with error message. So I though probably there should be a problem with my command and I am looking forward if you could check them and guide me accordingly.
      Another question is, in my specific case, do you have any suggestion of the command to use to gen the number of weeks (N)?

      Comment


      • #4
        Without a data example that reproduces the problem, all I can do is guess what is going wrong. I've already guessed once and it didn't help you. In what you post, all of the variables are strings, and string variables can't be used in regressions. However, you would have hit a snag long before that: your -xtset- command would not have worked and you never would have even gotten to the regression, nor been able to create those L1, F1, L2, and F2 variables. So I have nothing to work with: an unusable data tableau.

        So please post back with an example using -dataex-. There isn't anything useful I can do without that.

        Comment


        • #5
          Dear Schechter, thanks again for your attention and assistance. As adviced, I have check back my data and fix it accordingly and I was able to regress by excluding the variable with F2 and L2 as i do not have the data of 2022 to gen variable with F2, and I was able to generated the NCSKEW. However, the results of e n W W2 W3 TW2 ncskew first_last seem not accurate. I beleive that there should be a problem with my commands. following the commands and data for your reference. Thanks again for your time and assistance.

          bysort ID (Year) : gen t = _n
          xtset ID t
          ascol logRI, toweek returns(log) keep(all)
          ascol logRM, toweek returns(log) keep(all)
          bysort ID (t) : gen F1week_logRM = F1.week_logRM
          bysort ID (t) : gen L1week_logRM = L1.week_logRM
          reg week_logRI F1week_logRM week_logRM L1week_logRM
          predict double e, residuals
          gen double W = ln(1+e)
          gen double W2 = W^2
          gen double W3 = W^3
          egen double TW2 = total(W2)
          egen double TW3 = total(W3)
          gen ncskew = -(n*(n-1)^1.5*TW3)/((n-1)*(n-2)*TW2^1.5)
          * bysort ID (week_id): gen first_last = _n == 1 | _n == _N
          list week_id e-ncskew if first_last


          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte ID int Year double logRI byte t str6 week_id double(week_logRI logRM) str6 I double(week_logRM F1week_logRM L1week_logRM e) float n double(W W2 W3 TW2) float(ncskew first_last)
           1 2019 -.02896046 1 "1960w1" -.20050093  3.0460948 "1960w1"  11.317394  11.31739  11.31739  -.05837987304178213 170  -.06015334799028496  .0036184252744403196  -.00021766039471025092 8.40483170588753 1.6983132 1
           1 2020 -.17154048 2 "1960w1" -.20050093  2.8060969 "1960w1"  11.317394  11.31739  11.31739  -.05837987304178213 170  -.06015334799028496  .0036184252744403196  -.00021766039471025092 8.40483170588753 1.6983132 1
           2 2019  .25159463 1 "1960w1"  .25159463  .50033136 "1960w1"  1.6175254  1.617525  1.617525    .3544782581910873 170    .3034163308756747    .09206146984205692      .02793295339449849 8.40483170588753 1.6983132 1
           2 2020          . 2 "1960w1"  .25159463          . "1960w1"  1.6175254  1.617525  1.617525    .3544782581910873 170    .3034163308756747    .09206146984205692      .02793295339449849 8.40483170588753 1.6983132 1
           3 2019 -.07646284 1 "1960w1" -.07646284  .99363134 "1960w1"  3.9458051  3.945805  3.945805   .03583903009167411 170   .03521175540574647  .0012398677187541157  .000043657918848250774 8.40483170588753 1.6983132 1
           3 2020          . 2 "1960w1" -.07646284  1.0383808 "1960w1"  3.9458051  3.945805  3.945805   .03583903009167411 170   .03521175540574647  .0012398677187541157  .000043657918848250774 8.40483170588753 1.6983132 1
           4 2019 -.06927958 1 "1960w1" -.27866208  1.9746441 "1960w1"  7.8581584  7.858159  7.858159  -.15053415181918867 170  -.16314754093748085    .02661712011394699    -.004342517693428011 8.40483170588753 1.6983132 1
           4 2020  -.2093825 2 "1960w1" -.27866208  1.9226998 "1960w1"  7.8581584  7.858159  7.858159  -.15053415181918867 170  -.16314754093748085    .02661712011394699    -.004342517693428011 8.40483170588753 1.6983132 1
           5 2019 -.03636426 1 "1960w1" -.41250036  .66949904 "1960w1"  2.4661771  2.466177  2.466177  -.30618380792096905 170   -.3655482064671184      .133625491251327    -.048846558665210205 8.40483170588753 1.6983132 1
           5 2020  -.3761361 2 "1960w1" -.41250036  .61503601 "1960w1"  2.4661771  2.466177  2.466177  -.30618380792096905 170   -.3655482064671184      .133625491251327    -.048846558665210205 8.40483170588753 1.6983132 1
           6 2019  .13094121 1 "1960w1"  .01450918  1.9091866 "1960w1"  7.6347447  7.634745  7.634745   .14173336613018694 170   .13254760422728346   .017568867386392573    .0023287112810531905 8.40483170588753 1.6983132 1
           6 2020 -.11643202 2 "1960w1"  .01450918  1.9136919 "1960w1"  7.6347447  7.634745  7.634745   .14173336613018694 170   .13254760422728346   .017568867386392573    .0023287112810531905 8.40483170588753 1.6983132 1
           7 2019  .10238441 1 "1960w1"  .10238441  .26856842 "1960w1"  .52473754  .5247375  .5247375   .20084754678212793 170    .1830275964743766    .03349910107118724     .006131259953111616 8.40483170588753 1.6983132 1
           7 2020          . 2 "1960w1"  .10238441          . "1960w1"  .52473754  .5247375  .5247375   .20084754678212793 170    .1830275964743766    .03349910107118724     .006131259953111616 8.40483170588753 1.6983132 1
           8 2019 -.34919884 1 "1960w1" -.34684136          . "1960w1"          0         0         0  -.25050086556451057 170  -.28835011629606955    .08314578956795683     -.02397509809144888 8.40483170588753 1.6983132 1
           8 2020  .00235748 2 "1960w1" -.34684136          . "1960w1"          0         0         0  -.25050086556451057 170  -.28835011629606955    .08314578956795683     -.02397509809144888 8.40483170588753 1.6983132 1
           9 2019 -.03501527 1 "1960w1"  -.0217258  .15368735 "1960w1"  .69766942  .6976694  .6976694   .07743687227099692 170   .07458495405997512   .005562915372128599    .0004149097874697409 8.40483170588753 1.6983132 1
           9 2020  .01328947 2 "1960w1"  -.0217258  .16541814 "1960w1"  .69766942  .6976694  .6976694   .07743687227099692 170   .07458495405997512   .005562915372128599    .0004149097874697409 8.40483170588753 1.6983132 1
          10 2019          . 1 "1960w1"          0          . "1960w1"  1.8129057  1.812906  1.812906   .10367397091838476 170   .09864458804337321    .00973075475024681    .0009598862936891936 8.40483170588753 1.6983132 1
          10 2020          . 2 "1960w1"          0          . "1960w1"  1.8129057  1.812906  1.812906   .10367397091838476 170   .09864458804337321    .00973075475024681    .0009598862936891936 8.40483170588753 1.6983132 1
          11 2019 -.17036315 1 "1960w1" -.60340881  3.8635094 "1960w1"  15.690812  15.69081  15.69081  -.44359661882952217 170   -.5862617420812957    .34370283022819564      -.2014998200078538 8.40483170588753 1.6983132 1
          11 2020 -.43304566 2 "1960w1" -.60340881  3.9480549 "1960w1"  15.690812  15.69081  15.69081  -.44359661882952217 170   -.5862617420812957    .34370283022819564      -.2014998200078538 8.40483170588753 1.6983132 1
          12 2019          . 1 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          12 2020          . 2 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          13 2019          . 1 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          13 2020          . 2 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          14 2019 -.14427032 1 "1960w1" -.74760605          . "1960w1"  6.3292921  6.329292  6.329292   -.6256626161679798 170   -.9825977924039514     .9654984216371187      -.9486966176701324 8.40483170588753 1.6983132 1
          14 2020 -.60333572 2 "1960w1" -.74760605  3.1239467 "1960w1"  6.3292921  6.329292  6.329292   -.6256626161679798 170   -.9825977924039514     .9654984216371187      -.9486966176701324 8.40483170588753 1.6983132 1
          15 2019  -.0672695 1 "1960w1"  -.0811913  1.5502279 "1960w1"   6.472462  6.472462  6.472462  .041331277631230776 170   .04049996920164891  .0016402475053345102   .00006642997344912912 8.40483170588753 1.6983132 1
          15 2020  -.0139218 2 "1960w1"  -.0811913  1.7070744 "1960w1"   6.472462  6.472462  6.472462  .041331277631230776 170   .04049996920164891  .0016402475053345102   .00006642997344912912 8.40483170588753 1.6983132 1
          16 2019 -.15352999 1 "1960w1" -.13355407          . "1960w1"  2.4483831  2.448383  2.448383 -.027309497329791377 170 -.027689333038229076  .0007666991641019642 -.000021229388494951134 8.40483170588753 1.6983132 1
          16 2020  .01997592 2 "1960w1" -.13355407  1.1716132 "1960w1"  2.4483831  2.448383  2.448383 -.027309497329791377 170 -.027689333038229076  .0007666991641019642 -.000021229388494951134 8.40483170588753 1.6983132 1
          17 2019  .03460496 1 "1960w1"  .02639994  1.8341263 "1960w1"  7.3610541  7.361054  7.361054   .15251700645005714 170   .14194825191867402   .020149306222767345    .0028601587956958853 8.40483170588753 1.6983132 1
          17 2020 -.00820502 2 "1960w1"  .02639994  1.8408431 "1960w1"  7.3610541  7.361054  7.361054   .15251700645005714 170   .14194825191867402   .020149306222767345    .0028601587956958853 8.40483170588753 1.6983132 1
          18 2019          . 1 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          18 2020          . 2 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          19 2019 -.09523548 1 "1960w1" -.00120774  1.4295416 "1960w1"  5.7000187  5.700019  5.700019    .1181901881941861 170   .11171147492890031   .012479453630790322     .001394098171402407 8.40483170588753 1.6983132 1
          19 2020  .09402775 2 "1960w1" -.00120774  1.4291891 "1960w1"  5.7000187  5.700019  5.700019    .1181901881941861 170   .11171147492890031   .012479453630790322     .001394098171402407 8.40483170588753 1.6983132 1
          20 2019 -.05411317 1 "1960w1" -.09872644  1.6665905 "1960w1"  6.6829967  6.682997  6.682997  .024647782187968287 170  .024348926403349888  .0005928702169957493  .000014435753280367577 8.40483170588753 1.6983132 1
          20 2020 -.04461327 2 "1960w1" -.09872644  1.6760269 "1960w1"  6.6829967  6.682997  6.682997  .024647782187968287 170  .024348926403349888  .0005928702169957493  .000014435753280367577 8.40483170588753 1.6983132 1
          21 2019 -.03242314 1 "1960w1"  .01763846  1.7980786 "1960w1"  5.6678178  5.667818  5.667818   .13690613070595709 170    .1283106526143781   .016463623574327613    .0021124582852194364 8.40483170588753 1.6983132 1
          21 2020   .0500616 2 "1960w1"  .01763846  1.9164656 "1960w1"  5.6678178  5.667818  5.667818   .13690613070595709 170    .1283106526143781   .016463623574327613    .0021124582852194364 8.40483170588753 1.6983132 1
          22 2019 -.23705002 1 "1960w1" -.36012182  1.4053875 "1960w1"   6.020752  6.020752  6.020752  -.23942647732207575 170  -.27368249519313004    .07490210817513765    -.020499395860597416 8.40483170588753 1.6983132 1
          22 2020  -.1230718 2 "1960w1" -.36012182  1.5065768 "1960w1"   6.020752  6.020752  6.020752  -.23942647732207575 170  -.27368249519313004    .07490210817513765    -.020499395860597416 8.40483170588753 1.6983132 1
          23 2019 -.07207105 1 "1960w1"  .01807718  1.2738975 "1960w1"  5.4874302   5.48743   5.48743   .13661515570725644 170   .12805468404084558    .01639800210480079     .002099840978431386 8.40483170588753 1.6983132 1
          23 2020  .09014823 2 "1960w1"  .01807718  1.4165899 "1960w1"  5.4874302   5.48743   5.48743   .13661515570725644 170   .12805468404084558    .01639800210480079     .002099840978431386 8.40483170588753 1.6983132 1
          24 2019 -.10435527 1 "1960w1" -.10435527 -.38717378 "1960w1" -.76363272 -.7636327 -.7636327 -.011103784879054293 170  -.01116589207629744 .00012467714585952198 -1.3921315550482167e-06 8.40483170588753 1.6983132 1
          24 2020          . 2 "1960w1" -.10435527          . "1960w1" -.76363272 -.7636327 -.7636327 -.011103784879054293 170  -.01116589207629744 .00012467714585952198 -1.3921315550482167e-06 8.40483170588753 1.6983132 1
          25 2019 -.07256489 1 "1960w1"  .00920778  2.1784761 "1960w1"  8.6839309   8.68393   8.68393   .14067608226037415 170    .1316211412333771     .0173241248195766     .002280221079622145 8.40483170588753 1.6983132 1
          25 2020  .08177266 2 "1960w1"  .00920778  2.2277542 "1960w1"  8.6839309   8.68393   8.68393   .14067608226037415 170    .1316211412333771     .0173241248195766     .002280221079622145 8.40483170588753 1.6983132 1
          26 2019 -.05351281 1 "1960w1" -.17105341   1.411919 "1960w1"  5.8558195   5.85582   5.85582  -.05102524411456702 170  -.05237308147898387  .0027429396636042833  -.00014365620249388373 8.40483170588753 1.6983132 1
          26 2020  -.1175406 2 "1960w1" -.17105341  1.5698078 "1960w1"  5.8558195   5.85582   5.85582  -.05102524411456702 170  -.05237308147898387  .0027429396636042833  -.00014365620249388373 8.40483170588753 1.6983132 1
          27 2019 -.03566278 1 "1960w1" -.05772474  .85385466 "1960w1"  3.4200545  3.420054  3.420054   .05245038976482308 170    .0511211498481113    .00261337196179305    .0001335985796676751 8.40483170588753 1.6983132 1
          27 2020 -.02206196 2 "1960w1" -.05772474  .87079393 "1960w1"  3.4200545  3.420054  3.420054   .05245038976482308 170    .0511211498481113    .00261337196179305    .0001335985796676751 8.40483170588753 1.6983132 1
          28 2019 -.14888481 1 "1960w1" -.00069803  .95102737 "1960w1"   4.016866  4.016866  4.016866   .11189129213013556 170   .10606243217390296   .011249239518643766    .0011931217034541431 8.40483170588753 1.6983132 1
          28 2020  .14818678 2 "1960w1" -.00069803   1.063955 "1960w1"   4.016866  4.016866  4.016866   .11189129213013556 170   .10606243217390296   .011249239518643766    .0011931217034541431 8.40483170588753 1.6983132 1
          29 2019          . 1 "1960w1"          0          . "1960w1"   1.289666  1.289666  1.289666   .10155738756004062 170   .09672498536753446   .009355722794349755    .0009049321503861886 8.40483170588753 1.6983132 1
          29 2020          . 2 "1960w1"          0  .61904607 "1960w1"   1.289666  1.289666  1.289666   .10155738756004062 170   .09672498536753446   .009355722794349755    .0009049321503861886 8.40483170588753 1.6983132 1
          30 2019  .03644933 1 "1960w1"  .01646959  1.6052633 "1960w1"  6.6147265  6.614727  6.614727   .13956764895113663 170   .13064893516490148    .01706914425972263     .002230065521708852 8.40483170588753 1.6983132 1
          30 2020 -.01997974 2 "1960w1"  .01646959  1.6599878 "1960w1"  6.6147265  6.614727  6.614727   .13956764895113663 170   .13064893516490148    .01706914425972263     .002230065521708852 8.40483170588753 1.6983132 1
          31 2019 -.16075706 1 "1960w1" -.33512126  1.6953697 "1960w1"  6.7793265  6.779326  6.779326  -.21135736926892876 170  -.23744200024869053   .056378703482099155    -.013386672126217436 8.40483170588753 1.6983132 1
          31 2020  -.1743642 2 "1960w1" -.33512126  1.7525804 "1960w1"  6.7793265  6.779326  6.779326  -.21135736926892876 170  -.23744200024869053   .056378703482099155    -.013386672126217436 8.40483170588753 1.6983132 1
          32 2019  .01627953 1 "1960w1" -.07339427  1.2818159 "1960w1"  4.9872155  4.987216  4.987216   .04312026194024275 170   .04221647324532934  .0017822306132736078   .00007523949100227215 8.40483170588753 1.6983132 1
          32 2020 -.08967381 2 "1960w1" -.07339427  1.2486762 "1960w1"  4.9872155  4.987216  4.987216   .04312026194024275 170   .04221647324532934  .0017822306132736078   .00007523949100227215 8.40483170588753 1.6983132 1
          33 2019 -.04438588 1 "1960w1" -.00953821  1.0969271 "1960w1"   4.438776  4.438776  4.438776   .10475780159715989 170   .09962612687040787   .009925365155198604    .0009888256881869415 8.40483170588753 1.6983132 1
          33 2020  .03484767 2 "1960w1" -.00953821  1.1551073 "1960w1"   4.438776  4.438776  4.438776   .10475780159715989 170   .09962612687040787   .009925365155198604    .0009888256881869415 8.40483170588753 1.6983132 1
          34 2019 -.02654503 1 "1960w1" -.00209558  1.6327101 "1960w1"  5.9113963  5.911397  5.911397   .11815740240831916 170   .11168215409701623    .01247290354374968    .0013930007356102716 8.40483170588753 1.6983132 1
          34 2020  .02444944 2 "1960w1" -.00209558  1.7748827 "1960w1"  5.9113963  5.911397  5.911397   .11815740240831916 170   .11168215409701623    .01247290354374968    .0013930007356102716 8.40483170588753 1.6983132 1
          35 2019          . 1 "1960w1"          0  1.1503026 "1960w1"  4.3816378  4.381638  4.381638   .11406487897621057 170    .1080153794647147   .011667322200906311    .0012602502348679856 8.40483170588753 1.6983132 1
          35 2020          . 2 "1960w1"          0     1.0525 "1960w1"  4.3816378  4.381638  4.381638   .11406487897621057 170    .1080153794647147   .011667322200906311    .0012602502348679856 8.40483170588753 1.6983132 1
          36 2019   .0143509 1 "1960w1"  .06048451 -.20958106 "1960w1"  -.6462175 -.6462175 -.6462175   .15421095736228235 170   .14341695671898036   .020568423474533887    .0029498606992248862 8.40483170588753 1.6983132 1
          36 2020  .04613361 2 "1960w1"  .06048451  -.1241123 "1960w1"  -.6462175 -.6462175 -.6462175   .15421095736228235 170   .14341695671898036   .020568423474533887    .0029498606992248862 8.40483170588753 1.6983132 1
          37 2019 -.02255672 1 "1960w1"  .01743618  1.6952624 "1960w1"   6.944581  6.944581  6.944581   .14186855006203844 170   .13266599958424205   .017600267445686112    .0023349570736319425 8.40483170588753 1.6983132 1
          37 2020   .0399929 2 "1960w1"  .01743618  1.7808875 "1960w1"   6.944581  6.944581  6.944581   .14186855006203844 170   .13266599958424205   .017600267445686112    .0023349570736319425 8.40483170588753 1.6983132 1
          38 2019  .00732729 1 "1960w1" -.09481191  .81122328 "1960w1"  3.2292956  3.229295  3.229295  .014591571296260708 170   .01448613870047247 .00020984821444932624  3.0398903405594314e-06 8.40483170588753 1.6983132 1
          38 2020 -.10213921 2 "1960w1" -.09481191    .775567 "1960w1"  3.2292956  3.229295  3.229295  .014591571296260708 170   .01448613870047247 .00020984821444932624  3.0398903405594314e-06 8.40483170588753 1.6983132 1
          39 2019 -.00394273 1 "1960w1" -.01805989  1.3093026 "1960w1"  5.4730589  5.473059  5.473059    .1004199516352092 170   .09569188116091891   .009156936120115427    .0008762444430042113 8.40483170588753 1.6983132 1
          39 2020 -.01411717 2 "1960w1" -.01805989  1.3032141 "1960w1"  5.4730589  5.473059  5.473059    .1004199516352092 170   .09569188116091891   .009156936120115427    .0008762444430042113 8.40483170588753 1.6983132 1
          40 2019 -.16571023 1 "1960w1" -.15354493  .86272514 "1960w1"  3.5699107  3.569911  3.569911  -.04276360934586808 170   -.0437049058538916  .0019101187956975282  -.00008348156213570927 8.40483170588753 1.6983132 1
          40 2020   .0121653 2 "1960w1" -.15354493  .89100056 "1960w1"  3.5699107  3.569911  3.569911  -.04276360934586808 170   -.0437049058538916  .0019101187956975282  -.00008348156213570927 8.40483170588753 1.6983132 1
          41 2019          . 1 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          41 2020          . 2 "1960w1"          0          . "1960w1"          0         0         0   .09634049443548942 170   .09197781038323281    .00845991760289393    .0007781246971367514 8.40483170588753 1.6983132 1
          42 2019 -.02988243 1 "1960w1" -.11151605          . "1960w1"  1.0665612  1.066561  1.066561 -.010861154943579976 170 -.010920567873935309 .00011925880268922794 -1.3023738493319725e-06 8.40483170588753 1.6983132 1
          42 2020 -.08163362 2 "1960w1" -.11151605  .51174381 "1960w1"  1.0665612  1.066561  1.066561 -.010861154943579976 170 -.010920567873935309 .00011925880268922794 -1.3023738493319725e-06 8.40483170588753 1.6983132 1
          43 2019          . 1 "1960w1" -.63910639  .89090408 "1960w1"  2.6159457  2.615946  2.615946   -.5321840013868481 170   -.7596802257307664     .5771140453663482      -.4384221282563032 8.40483170588753 1.6983132 1
          43 2020 -.63910639 2 "1960w1" -.63910639  .78218703 "1960w1"  2.6159457  2.615946  2.615946   -.5321840013868481 170   -.7596802257307664     .5771140453663482      -.4384221282563032 8.40483170588753 1.6983132 1
          44 2019 -.12567221 1 "1960w1" -.25643825          . "1960w1"          0         0         0  -.16009775556451056 170  -.17446976958898808    .03043970050043459    -.005310807532668628 8.40483170588753 1.6983132 1
          44 2020 -.13076604 2 "1960w1" -.25643825          . "1960w1"          0         0         0  -.16009775556451056 170  -.17446976958898808    .03043970050043459    -.005310807532668628 8.40483170588753 1.6983132 1
          45 2019  -.0342682 1 "1960w1" -.24190453  .45224178 "1960w1"  1.8966712  1.896671  1.896671  -.13789171502352224 170  -.14837439558568966    .02201496126541872   -.0032664565715988724 8.40483170588753 1.6983132 1
          45 2020 -.20763633 2 "1960w1" -.24190453  .49923951 "1960w1"  1.8966712  1.896671  1.896671  -.13789171502352224 170  -.14837439558568966    .02201496126541872   -.0032664565715988724 8.40483170588753 1.6983132 1
          46 2019  -.0997014 1 "1960w1"  .70370121  2.6623214 "1960w1"  6.8498662  6.849866  6.849866    .8277504444370678 170    .6030859453520125     .3637126574811307      .21934999187350043 8.40483170588753 1.6983132 1
          46 2020  .80340261 2 "1960w1"  .70370121  .76446444 "1960w1"  6.8498662  6.849866  6.849866    .8277504444370678 170    .6030859453520125     .3637126574811307      .21934999187350043 8.40483170588753 1.6983132 1
          47 2019 -2.6951088 1 "1960w1" -1.1379815  1.4820685 "1960w1"  5.8691154  5.869115  5.869115  -1.0178995501974173 170                    .                     .                       . 8.40483170588753 1.6983132 1
          47 2020  1.5571273 2 "1960w1" -1.1379815  1.4361469 "1960w1"  5.8691154  5.869115  5.869115  -1.0178995501974173 170                    .                     .                       . 8.40483170588753 1.6983132 1
          48 2019  .01869431 1 "1960w1" -.27770105  1.6944233 "1960w1"  6.7799148  6.779915  6.779915  -.15393477950686235 170    -.167158829565923   .027942074301849296    -.004670764435941183 8.40483170588753 1.6983132 1
          48 2020 -.29639535 2 "1960w1" -.27770105  1.6529194 "1960w1"  6.7799148  6.779915  6.779915  -.15393477950686235 170    -.167158829565923   .027942074301849296    -.004670764435941183 8.40483170588753 1.6983132 1
          49 2019 -.33638049 1 "1960w1"  -.2693619 -.22269258 "1960w1" -.71186701  -.711867  -.711867   -.1759010147889639 170   -.1934646286041215   .037428562520930665    -.007241102947297993 8.40483170588753 1.6983132 1
          49 2020  .06701858 2 "1960w1"  -.2693619 -.23892575 "1960w1" -.71186701  -.711867  -.711867   -.1759010147889639 170   -.1934646286041215   .037428562520930665    -.007241102947297993 8.40483170588753 1.6983132 1
          50 2019 -.02174526 1 "1960w1" -.09694244  .77700732 "1960w1"  3.0837914  3.083791  3.083791  .011872454902129723 170  .011802530217079502 .00013929971952507473   1.644089148925394e-06 8.40483170588753 1.6983132 1
          50 2020 -.07519718 2 "1960w1" -.09694244  .76956416 "1960w1"  3.0837914  3.083791  3.083791  .011872454902129723 170  .011802530217079502 .00013929971952507473   1.644089148925394e-06 8.40483170588753 1.6983132 1
          end

          Comment


          • #6
            I can't contribute much to the discussion at this point. Your goal, apparently, is to calculate this variable ncskew: it is not something I have heard of before and I have no way to know if your calculations for it are correct. Also, your code involves a user-written command -ascol- that I know nothing about.

            From a very general computing/statistics perspective, I can make the following observations about this:

            The command -gen double W = ln(1+e)- looks problematic. If e <= -1, then 1+e <= 0, and so W will be undefined. I notice that in the example data there are 2 such observations.

            The calculations of TW2 and TW3 are sums of W2 and W3, respectively, over the entire data set. This seems odd since I was under the impression that what you are trying to calculate is to be done for each firm, not for the data set as a whole. Did you omit -by ID:- from these commands?

            I hope this is helpful. It's the best I can do at this point.

            Added: There is also something peculiar in the data. The commands
            Code:
            bysort ID (t) : gen F1week_logRM = F1.week_logRM
            bysort ID (t) : gen L1week_logRM = L1.week_logRM
            look correct. (The -bysort- prefixes are unnecessary, because the use of the time-series operators implies this automatically. But they do no harm either.) But they do not produce the results you show in the data set. Because your data are for only two years, there are no observations that have both a forward and a lag. The 2019 observations have a forward, but no lag, and the 2020 observations have a lag but no forward. Yet you show no missing values in either the F1week_logRM or L1week_logRM variables. So the data are not consistent with having been generated by the code you show. Of course, if you then try to run the regression with these missing values you will, once again, end up with no observations, because every observation will be missing one of those variables.

            Looking beyond that, however, what is particularly weird is that the value of week_logRM is always the same for both years in each ID. Since I don't even know what RM is, I can't assert confidently that this must be wrong, but it is unusual to see that for any variable in any financial data set. In fact, I notice that all of the variables in your regression command have this exact property: they do not vary over time within ID. Again, this is odd, and suggests something is wrong. I also note that because week_logRM == F1week_logRM == L1week_logRM within each ID, two of those three variables must get omitted due to multicolinearity. So you end up regressing just week_logRI on week_logRM, and in the estimation sample every observation appears, exactly duplicated, twice. It is just really hard to imagine that this is correct.

            Again, except for the calculation of W, the code itself looks plausible. But I cannot help thinking that the data set is seriously wrong.


            Last edited by Clyde Schechter; 20 Sep 2022, 09:29.

            Comment


            • #7
              Dear Schechter, thanks again for your time and assistance and sorry that because the time zone difference, we could not interact dirrectly to save time. My current issue is related to the discussion on statalist on the following link https://www.statalist.org/forums/for...rangerun/page2 and could be solve following the advice of Robert Picard that Ihave followed by cross checking the commands I used, however, till now, I still fail to identify the problem with the commands that I used. RM is the market return or market indecex and RI is firm return. Both of them were on daily frequency (end of the year), that is why I used the ascol command to convert them into weekly frenquency. I also learned about this method through statalist discussion on the following link https://www.statalist.org/forums/for...e-months/page2 given by Attaullah Shah and you was also part of the discussion. However, I have just realized that the problem is started from using this command "ascol" to convert my daily return into weekly frequency. I have tried again with bysort ID and get the error message that 'ascol may not be combined with by'. Now that I know somehow the origin of the problem is, I would be happy if you could assist me to convert the dayly frenquency firm return (logRI) and market return (logRM) respectivelly into weekly frenquency. the daily frenquency firm return and the daily stock return are respectivelly the average daily firm return end of the year log(P1/P0), and the average daily stock market return end of the year log(RM/N_days), with N_days, the number of trading days in each year. in Addition, I will looking to convert N_days to N_weeks. I attached the dataex example data for your reference.

              Regarding the data, I created a separate file with the data of market indeces (RM) of respectivelly the years 2018, 2019, 2020, and 2021 and then generate the lag (F1logRM) and lead (F1logRM) respectivelly for the year 2019 and 2020 before copy past it in the data file containing orther variable accordingly.

              In fact the problem you tried to expose
              Looking beyond that, however, what is particularly weird is that the value of week_logRM is always the same for both years in each ID. Since I don't even know what RM is, I can't assert confidently that this must be wrong, but it is unusual to see that for any variable in any financial data set. In fact, I notice that all of the variables in your regression command have this exact property: they do not vary over time within ID. Again, this is odd, and suggests something is wrong. I also note that because week_logRM == F1week_logRM == L1week_logRM within each ID, two of those three variables must get omitted due to multicolinearity. So you end up regressing just week_logRI on week_logRM, and in the estimation sample every observation appears, exactly duplicated, twice. It is just really hard to imagine that this is correct.
              Is what made me realised that something was wrong with my commands and I am seeking for help to possibily identify the issue and correct it.

              The calculations of TW2 and TW3 are sums of W2 and W3, respectively, over the entire data set. This seems odd since I was under the impression that what you are trying to calculate is to be done for each firm, not for the data set as a whole. Did you omit -by ID:- from these commands?
              Yes, you are right. I need to run the regression by each firm. Thanks for the remarks, I will take it into account after solve the issue of converting the the logRI and logRM from daily frequency to weekly frequency.

              bysort ID : gen t_d = _n
              xtset ID t_d
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input byte ID int Year str5 N_days double(logRI logRM) float t_d
               1 2019 "186"   -.02896046  3.0460948 1
               1 2020 ""      -.17154048  2.8060969 2
               2 2020 "186"   -.06186635  1.0309779 1
               2 2019 "251"    .25159463   1.111734 2
               3 2019 "243"   -.07646284  .99363134 1
               3 2020 "254"            .  1.0383808 2
               4 2019 ""      -.06927958  1.9746441 1
               4 2020 "252"    -.2093825  1.9226998 2
               5 2019 "251"   -.03636426  .66949904 1
               5 2020 "162"    -.3761361  .61503601 2
               6 2020 "243"   -.11643202  1.9136919 1
               6 2019 ""       .13094121  1.9091866 2
               7 2020 ""      -.25592563 -2.8328636 1
               7 2019 "295"    .10041482 -2.7359536 2
               8 2020 "253"    .00098584          . 1
               8 2019 "253"    -.3478272          . 2
               9 2019 "251.5" -.03501527  .15368735 1
               9 2020 "249"    .01328947  .16541814 2
              10 2020 "255"   -.44256421          . 1
              10 2019 "248"   -.17036315  3.8635094 2
              11 2020 "189"            .          . 1
              11 2019 "211"            .          . 2
              12 2020 "207"   -.17236339          . 1
              12 2019 ""               .          . 2
              13 2019 "248"            .          . 1
              13 2020 "161"    .01564689          . 2
              14 2019 "243"   -.14427032          . 1
              14 2020 "248"   -.60333572          . 2
              15 2020 "243"    -.0139218  1.7070744 1
              15 2019 "252"    -.0672695  1.5515178 2
              16 2019 "252"   -.36596702          . 1
              16 2020 "241"    .23241295          . 2
              17 2020 "243"   -.29732782  1.8408431 1
              17 2019 "243"    .03460496  1.8341263 2
              18 2020 "252"            .          . 1
              18 2019 "245"            .  .05306301 2
              19 2020 "244"    .09389405  1.4291891 1
              19 2019 "243"   -.09510177  1.4295416 2
              20 2020 "251"   -.04461327  1.6760269 1
              20 2019 "213"   -.05411317  1.6665905 2
              21 2020 "201"     .0500616  1.9164656 1
              21 2019 "249"   -.03242314  1.7980786 2
              22 2020 "246"   -.15788183   1.510713 1
              22 2019 "236"   -.23705002  1.4053875 2
              23 2019 "255"   -.07207105  1.2738975 1
              23 2020 "254"    .09014823  1.4165899 2
              24 2020 "252"   -.15960585  .64151739 1
              24 2019 "251"   -.10435527  .58477886 2
              25 2019 "252"   -.07256489  2.1784761 1
              25 2020 "249"    .08177266  2.2277542 2
              26 2019 "251"   -.05351281   1.411919 1
              26 2020 "247"    -.1175406  1.5698078 2
              27 2020 "246"   -.02206196  .87079393 1
              27 2019 "258"   -.03566278  .85385466 2
              28 2020 "251"    .14818678   1.063955 1
              28 2019 "257"   -.14888481  .95102737 2
              29 2020 "250"   -.32586737          . 1
              29 2019 "242"            .          . 2
              30 2020 "252"   -.01979224  1.6599878 1
              30 2019 "246"    .03644933  1.6052633 2
              31 2020 "NA"     -.1743642  1.7525804 1
              31 2019 "NA"    -.16075706  1.6953697 2
              32 2019 "257"    .01627953  1.2818159 1
              32 2020 "247"   -.08967349  1.2486762 2
              33 2020 "251"    .03484767  1.1551073 1
              33 2019 "250"   -.04438588  1.0969271 2
              34 2020 "243"    .03455618  1.7748827 1
              34 2019 "253"   -.03665177  .84888285 2
              35 2019 "252"            .  1.1503026 1
              35 2020 "255"            .     1.0525 2
              36 2019 "262"     .0143509 -.20958106 1
              36 2020 "220"    .04613361  -.1241123 2
              37 2019 "250"   -.02255672  1.6952624 1
              37 2020 ""        .0399929  1.7808875 2
              38 2020 "249"   -.10213921    .775567 1
              38 2019 "251"    .00732729  .81122328 2
              39 2020 "252"   -.01411717  1.3032141 1
              39 2019 "244"   -.00394273  1.3093026 2
              40 2020 "242"     .0121653  .89100056 1
              40 2019 "246"   -.16571023  .86272514 2
              41 2020 "243"            .          . 1
              41 2019 "250"            .          . 2
              42 2019 "253"   -.02988243  .56951607 1
              42 2020 "252"   -.08163362  .51174381 2
              43 2019 "250"            .  .89090408 1
              43 2020 "167"   -.63606935  .78218703 2
              44 2019 "249"   -.12567221          . 1
              44 2020 "250"   -.13076604          . 2
              45 2019 "245"    -.0437986          . 1
              45 2020 "243"   -.32068138          . 2
              46 2020 "251"   -.20947622  .49923951 1
              46 2019 "250"   -.03242831   .5733194 2
              47 2019 "243"    -.0997014  2.6623214 1
              47 2020 "251"   -.00428491  .76789762 2
              48 2019 ""      -2.6951088  1.4820685 1
              48 2020 "243"    2.4577339  1.4378737 2
              49 2019 ""        .0179191  1.6944233 1
              49 2020 ""       -.1176746  1.6546531 2
              50 2019 "251"   -.33638049 -.19414718 1
              50 2020 "251"    .06701858 -.23892575 2
              51 2020 "251"   -.07519718  .76956416 1
              51 2019 "250"   -.02174526  .77700732 2
              52 2019 ""      -.05450709  1.1946903 1
              52 2020 "253"   -.01501665  1.1649971 2
              53 2019 "243"            .  .78465788 1
              53 2020 "242"   -.07667357  .75577305 2
              54 2019 "240"   -.02811263  .69128029 1
              54 2020 "242"   -.10783175    .644902 2
              55 2020 "248"   -.10857571 -.63796524 1
              55 2019 "246"   -.12559904 -.57229221 2
              56 2020 "240"   -.10016708  .36359718 1
              56 2019 "245"   -.03817597   .3520317 2
              57 2020 "244"   -.06444204  .99686909 1
              57 2019 ""      -.06427937  1.0454738 2
              58 2019 "246"   -.02288836  1.6773335 1
              58 2020 "254"   -.13357444  1.8851147 2
              59 2019 "243"            .          . 1
              59 2020 "243"    .50818712          . 2
              60 2020 "243"    .21200197  2.3900345 1
              60 2019 "251"    .06856314  2.3763039 2
              61 2019 "247"   -.10003991   1.935262 1
              61 2020 "247"   -.09763434  1.9063109 2
              62 2020 "245"   -.19496294          . 1
              62 2019 "231"   -.32986781          . 2
              63 2019 "250"    -.0220686  1.2214836 1
              63 2020 ""      -.07443693  1.1585552 2
              64 2019 "249"     1.420752  .41680821 1
              64 2020 "246"    .01944036  .41993601 2
              65 2020 "239"   -.00247148          . 1
              65 2019 "254"   -.12391787          . 2
              66 2019 "251"   -.56643807          . 1
              66 2020 "247"   -.13678704          . 2
              67 2020 "247"   -.01950038          . 1
              67 2019 "246"    1.2222699          . 2
              68 2020 "249"   -.09823211  1.1653951 1
              68 2019 "244"   -.96219789  1.1986124 2
              69 2019 ""      -1.1001889 -.16798666 1
              69 2020 "246"   -.16251629 -.20344851 2
              70 2020 "258"   -.06067532  .68758183 1
              70 2019 "251"            .  .71984358 2
              71 2019 "255"    1.3450184  .15159325 1
              71 2020 ""      -.02317123   .2282129 2
              72 2020 "240"   -.05021536          . 1
              72 2019 "250"    .28405568          . 2
              73 2020 "246"   -.05697526  .25495929 1
              73 2019 "253"   -.23740826  .30597937 2
              74 2020 ""       .07609599  1.1626472 1
              74 2019 "255"   -.03735899  1.1003159 2
              75 2020 "246"   -.14619333          . 1
              75 2019 "249"            .          . 2
              76 2020 "254"   -.02689597 -.13464971 1
              76 2019 "247"   -.14398225 -.02917237 2
              77 2020 ""       .56724496  1.5427969 1
              77 2019 "249"   -.24077301  1.5292704 2
              78 2019 "252"   -.07338555  1.7105404 1
              78 2020 "257"   -.08915439  1.7250874 2
              79 2020 "243"   -.05938966  .81565943 1
              79 2019 ""      -.02178922  .94167704 2
              80 2019 "249"   -.07250969   3.188966 1
              80 2020 "247"   -.09954481  3.7580543 2
              81 2020 "249"    .26020897  .69547806 1
              81 2019 "249"   -.09246899  .70065685 2
              82 2020 "246"   -.03217717  1.6443049 1
              82 2019 "241"   -.00504295  1.7539988 2
              83 2019 "245"   -.07253469  1.4599105 1
              83 2020 "243"   -.04995766  1.4522933 2
              84 2020 "249"   -.28188997  2.3581317 1
              84 2019 ""      -.16153449  2.3677231 2
              85 2019 "247"            .          . 1
              85 2020 "247"   -.04503829          . 2
              86 2019 ""      -.05150633  .91034679 1
              86 2020 ""       -.1094109  .83897146 2
              87 2020 ""      -.02409988          . 1
              87 2019 ""       .05417193          . 2
              end
              Thanks again for your attention and time.

              Comment


              • #8
                My understanding is that you are asking for help on aggregating daily returns to weekly returns. But the example data you show are returns for each ID in each of two years based on a number of days ranging from 161 to 295. That data isn't a starting point for that conversion.

                Comment


                • #9
                  Many thaks again for your time and assistance. In fact my current problem is similar to the discussion on the statalist on the following link https://www.statalist.org/forums/for...aily-to-weekly, specifically with the method you Clyde Schechter applied to solve this issue. I have tried to applied it but failed to understand as well, but I keep learning and hope I could solve my current issue relying on this method of yours Clyde Schechter.

                  Regarding the data, I will be happy if you have any suggestion of additional variables needed to deal with this issue accordingly. For intance, my data is a cross sectional data and the ID are the identifier of each stock market and refering to the discussion Clyde Schechter could be interpreted as the stock code.
                  Last edited by Bienmali Kombate; 21 Sep 2022, 19:24.

                  Comment


                  • #10
                    If you would like assistance with the process of converting daily returns to weekly returns, you need to post an example of your daily returns data. (Use -dataex-, of course.)

                    Comment


                    • #11
                      Many thaks again for your time and assistance. logRI is firm daily return and logRM is the stock market daily return. It is important to note that in my current case, the data is at stock market level not at firm level, i., e, the observations here are stock markets. The firm x on the stock market y daily return is the average share price end of the year on the stock market y of the year 1 (log) divided on the average share price end of the year on the stock market y of the year 0; and the stock y daily return is the average daily stock market return log(RM/N_d), with RM the stock return end of the year, and N_d the number of trading days in the year on the stock market y.

                      In addition in our current case, N_d which is the number of trading days can also be interpreted as the number of daily return. So knowing the average daily return end of year (log) and the number of daily return end of year, I was wondering if there could be ways to deduct the average weekly return end of the year and then the number of trading weeks end of the year.

                      But since this is running me crazy, I resolve to preceed my analysis with the daily return, however, I will still looking for assistance and ways to appropriately address this issue.


                      Thanks again Dear Clyde Schechter for your dedication and knowledge sharing

                      Comment


                      • #12
                        I'm sorry, but I don't follow this. If RM is the ratio of stock price at the end of N_d periods to the stock price at the beginning, then the geometric mean return per period is (RM)1/N_d. You could calculate this as exp((1/N_d)*log(RM)), but that is unnecessarily complicated code. It is simpler to just code it as RM^(1/N_d). (Behind the scenes, Stata might calculate that using a similar formula to the one just shown, or, depending on specific values there might be more efficient ways of doing it.)

                        The above is true whether the expanse of N_d periods is a year, or anything else, and whether each period is a day, or any other shorter unit of time. All that matters is that RM is the ratio of the price at the end of N_d periods to the price at the beginning.

                        Comment

                        Working...
                        X