Announcement

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

  • Problem with regression based on deciles with Newey-West correction / choosing the right lag

    Hello Guys,

    I have two questions that are related:

    1. Can I use the newey-west correction for a regression based on deciles?
    And if so, did I include the command right in the code below?
    A sample of my data is listed at the bottom as an overview (does not work with the code listed below).

    2. I choose lag(1) here as an example. But is there a way to calculate the "right" lag?

    Code:
    capture program drop my_regression
    program define my_regression
        newey week_return lag_turnover_week lag_week_return lag_vola_week, lag(1)
        tempname M
        matrix `M' = r(table)
        foreach v of varlist lag_turnover_week lag_week_return lag_vola_week {
            gen b_`v' = _b[`v']
            gen se_`v' = _se[`v']
            gen p_`v' = `M'[4, `=colnumb(`M', "`v'")']
        }
        gen rsq = e(r2)
        gen adj_rsq = e(r2_a)
        gen n_obs = e(N)
        exit
    end
    
    // CREATE STATA INTERNAL FORMAT WEEKLY VARIABLE
    gen int weekly_date = weekly(week_text, "YW")
    format weekly_date %tw
    
    // XTSET THE DATA SO LAGS ARE CALCULATED CORRECTLY
    xtset n_cusip weekly_date
    gen lag_week_return = L1.week_return
    gen lag_turnover_week = L1.turnover_week  
    gen lag_vola_week = L1.week_vola
    
    // CREATE DECILES OF TURNOVER FOR EACH WEEK
    by weekly_date, sort: egen byte decile = xtile(lag_turnover_week), nq(10)  // REQUIRES -egenmore- PACKAGE
    
    runby my_regression, by(decile) status

    The basics of my data set are:
    - My dataset contains „all“ stocks from the NYSE from 1960-2016 (CRSP data base), weekly data
    -> Since my dataset is fairly large I choose to upload a small sample via dataex.

    - Dependent variable: week_return
    - Predictor variables: lag_turnover_week, lag_week_return, lag_vola_week.

    A sample of my data set as an overview:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long permno str5 ticker str30 comnam long cusip int year byte week str7 week_text int n_cusip float(obs Cap_w week_return week_vola turnover_week)
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 25 "1992W25"     1  3103217 1.85e+07      -.08 .1396056 .0014523
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 26 "1992W26"     1  3103222 1.77e+07 -.1304348 .0404439 .0035169
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 27 "1992W27"     1  3103227 1.46e+07      -.25 .1387723 .0162756
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 28 "1992W28"     1  3103231 1.46e+07  .0666666 .1026101 .0063715
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 29 "1992W29"     1  3103236 1.48e+07       .25 .1772649 .0071558
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 30 "1992W30"     1  3103241 1.69e+07      -.35 .0858854 .0055808
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 31 "1992W31"     1  3103246 1.41e+07  .1538462 .1327449 .0074605
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 32 "1992W32"     1  3103251 1.50e+07  .1333333 .0766652 .0019607
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 33 "1992W33"     1  3103256 1.70e+07  .0588236 .0592826 .0050039
    78736 "ANAFF" "A & A FOODS LTD"                    2130 1992 34 "1992W34"     1  3103261 1.52e+07 -.2222222 .1419666 .0032383
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 22 "1992W22"     4 5.35e+07 3.36e+08  .0579712  .022273  .027345
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 23 "1992W23"     4 5.35e+07 3.39e+08 -5.48e-08 .0083603 .0145957
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 24 "1992W24"     4 5.35e+07 3.21e+08 -.0753424 .0232557 .0314104
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 25 "1992W25"     4 5.35e+07 3.00e+08 -.0370371 .0262223 .0514437
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 26 "1992W26"     4 5.35e+07 2.95e+08 -.0158855 .0245496 .0253961
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 27 "1992W27"     4 5.35e+07 2.95e+08 -.0196078 .0172911 .0183986
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 28 "1992W28"     4 5.35e+07 3.05e+08      .112 .0241555 .0273199
    11307 "SODA"  "A & W BRANDS INC"                  20910 1992 29 "1992W29"     4 5.35e+07 3.14e+08  .0035972 .0262156 .0296676
    76868 "AAON"  "AAON INC"                          36020 1992 26 "1992W26"     6   116288  5537500 -.1111111        . .0000903
    76868 "AAON"  "AAON INC"                          36020 1992 29 "1992W29"     6   116291  7960156  .1578947 .2450062 .0005056
    76868 "AAON"  "AAON INC"                          36020 1992 30 "1992W30"     6   116293  7752500  -.047619  .285468 .0014266
    76868 "AAON"  "AAON INC"                          36020 1992 31 "1992W31"     6   116298  7960156 -.0222222 .2723671 .0033634
    76868 "AAON"  "AAON INC"                          36020 1992 32 "1992W32"     6   116300  8306250  .1818181 .3055887 .0020497
    76868 "AAON"  "AAON INC"                          36020 1992 33 "1992W33"     6   116305  8306250  .0549451 .1115263 .0010158
    76868 "AAON"  "AAON INC"                          36020 1992 34 "1992W34"     6   116308  6921875  .0421052 .1823591 .0022799
    76868 "AAON"  "AAON INC"                          36020 1992 35 "1992W35"     6   116310  6921875       -.1 .1992756  .001377
    76868 "AAON"  "AAON INC"                          36020 1992 36 "1992W36"     6   116312  6575781  .1111112 .0785675  .000316
    76868 "AAON"  "AAON INC"                          36020 1992 37 "1992W37"     6   116314  6921875      .375 .0687465 .0023702
    76868 "AAON"  "AAON INC"                          36020 1992 38 "1992W38"     6   116316  7890938  .0909092 .0733715 .0050339
    54594 "AIR"   "A A R CORP"                        36110 1992 24 "1992W24"     7  2023129 1.96e+08  -.009901 .0301145 .0229303
    54594 "AIR"   "A A R CORP"                        36110 1992 25 "1992W25"     7  2023134 1.93e+08      -.03 .0157461 .0097068
    54594 "AIR"   "A A R CORP"                        36110 1992 26 "1992W26"     7  2023139 2.01e+08  .0927833 .0106077 .0158468
    54594 "AIR"   "A A R CORP"                        36110 1992 27 "1992W27"     7  2023144 2.11e+08 -.0188679  .016315 .0048754
    54594 "AIR"   "A A R CORP"                        36110 1992 28 "1992W28"     7  2023148 2.11e+08  .0096153 .0259035 .0108203
    54594 "AIR"   "A A R CORP"                        36110 1992 29 "1992W29"     7  2023153 2.05e+08 -.0095238 .0275444 .0075931
    54594 "AIR"   "A A R CORP"                        36110 1992  3 "1992W3"      7  2023027 2.18e+08  .0183486 .0188483 .0251148
    54594 "AIR"   "A A R CORP"                        36110 1992 30 "1992W30"     7  2023158 2.02e+08 -.0196154 .0191468 .0095684
    54594 "AIR"   "A A R CORP"                        36110 1992 31 "1992W31"     7  2023163 2.01e+08  .0099009 .0291023  .019571
    54594 "AIR"   "A A R CORP"                        36110 1992 32 "1992W32"     7  2023168 2.04e+08 -5.46e-08 .0068988 .0167149
    54594 "AIR"   "A A R CORP"                        36110 1992 33 "1992W33"     7  2023173 2.00e+08  5.27e-08 .0157666 .0057687
    54594 "AIR"   "A A R CORP"                        36110 1992 34 "1992W34"     7  2023178 2.01e+08  2.01e-08 .0099016  .004152
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 25 "1992W25"    10   238276 2.19e+07  -.076923 .0718943 .0068378
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 26 "1992W26"    10   238281 2.18e+07  .0416665 .1144077 .0082371
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 27 "1992W27"    10   238286 2.05e+07      -.08 .1342964 .0044189
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 28 "1992W28"    10   238290 2.06e+07  .0434783 .0469364 .0067238
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 29 "1992W29"    10   238295 2.04e+07  7.73e-08 .0984814 .0059312
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 30 "1992W30"    10   238300 1.99e+07 -.0833334 .1392759 .0154236
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 31 "1992W31"    10   238305 2.00e+07  .0909091 .0592746 .0075151
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 32 "1992W32"    10   238310 2.00e+07 -.0416667 .0556257 .0085988
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 33 "1992W33"    10   238315 1.90e+07 -.0434782 .0932249 .0161079
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 34 "1992W34"    10   238320 1.76e+07 -.1818182 .0621958  .013503
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 35 "1992W35"    10   238325 1.36e+07 -.1666666 .2536634 .0314989
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 36 "1992W36"    10   238330 1.58e+07  .5000001 .1461718 .0474985
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 37 "1992W37"    10   238334 2.35e+07  .3333335 .0696453 .0548957
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 38 "1992W38"    10   238339 2.16e+07       -.2 .1171543    .0148
    91783 "ABCC"  "AMERICAN BUSINESS COMPUTERS CP"    57310 1992 39 "1992W39"    10   238344 1.85e+07 -.1666666 .0715764 .0063045
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 30 "1992W30" 13522 3.22e+07 1.27e+09 -.0093897 .0093153 .0054159
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 31 "1992W31" 13522 3.22e+07 1.27e+09  .0276777 .0167343 .0208117
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 32 "1992W32" 13522 3.22e+07 1.24e+09 -.0744186 .0110105 .0204877
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 33 "1992W33" 13522 3.22e+07 1.22e+09  .0050252 .0150822 .0075576
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 34 "1992W34" 13522 3.22e+07 1.16e+09       -.1 .0165724  .009431
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 35 "1992W35" 13522 3.22e+07 1.04e+09 -.0666667 .0214454 .0250598
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 36 "1992W36" 13522 3.22e+07 1.07e+09  .0476191 .0320749 .0222869
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 37 "1992W37" 13522 3.22e+07 1.10e+09  .0340908 .0133348 .0192395
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 38 "1992W38" 13522 3.22e+07 1.08e+09 -.0274725 .0185182 .0063196
    47395 "KEM"   "KEMPER CORP"                    48839610 1992 39 "1992W39" 13522 3.22e+07 1.11e+09  .0282486 .0211116 .0133016
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 30 "1992W30" 13523 5.97e+07 1.86e+09  .0141845 .0125105 .0017953
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 31 "1992W31" 13523 5.97e+07 1.85e+09 -.0069929 .0090957 .0010786
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 32 "1992W32" 13523 5.97e+07 1.90e+09  .0507617  .025816 .0025953
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 33 "1992W33" 13523 5.97e+07 1.91e+09 -.0067569 .0056696  .002593
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 34 "1992W34" 13523 5.97e+07 1.90e+09 -.0068028 .0061965 .0030784
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 35 "1992W35" 13523 5.97e+07 1.85e+09 -.0239726 .0067484 .0016572
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 36 "1992W36" 13523 5.97e+07 1.89e+09  .0456141 .0110694 .0066535
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 37 "1992W37" 13523 5.97e+07 1.93e+09  .0067114 .0091105 .0067916
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 38 "1992W38" 13523 5.97e+07 1.93e+09 -.0366666 .0180135 .0078764
    76136 "UNIT"  "UNITRIN INC"                    48840110 1992 39 "1992W39" 13523 5.97e+07 1.86e+09 -.0034602 .0135426  .004401
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 24 "1992W24" 13526 3.31e+07 3.36e+07 -.0086956  .046358 .0015746
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 25 "1992W25" 13526 3.31e+07 3.39e+07  7.23e-08 .0173929 .0048305
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 26 "1992W26" 13526 3.31e+07 3.32e+07 -.0475978 .0097873 .0029847
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 27 "1992W27" 13526 3.31e+07 3.37e+07 -.0086957 .0100849 .0035208
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 28 "1992W28" 13526 3.31e+07 3.30e+07 -.0175439 .0124054 .0009322
    10749 "KTCO"  "KENAN TRANSPORT CO"             48853910 1992 29 "1992W29" 13526 3.31e+07 3.36e+07 -.0086957        . .0008644
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 25 "1992W25" 13529 3.30e+07 1.24e+08    -.0625 .0527641 .0275336
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 26 "1992W26" 13529 3.30e+07 1.28e+08 -.0111111 .0486729 .0177695
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 27 "1992W27" 13529 3.30e+07 1.17e+08 -.1235955 .0334867 .0073548
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 28 "1992W28" 13529 3.30e+07 1.01e+08 -.1025641 .0486881 .0156644
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 29 "1992W29" 13529 3.30e+07 1.05e+08  .0285715 .0462611 .0116126
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 30 "1992W30" 13529 3.30e+07 1.05e+08  .0833333 .0265173 .0035656
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 31 "1992W31" 13529 3.30e+07 1.15e+08  .0512821  .024098 .0076549
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 32 "1992W32" 13529 3.30e+07 1.11e+08  -.097561 .0524801 .0058881
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 33 "1992W33" 13529 3.30e+07 1.03e+08  -.027027 .0402206 .0015847
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 34 "1992W34" 13529 3.30e+07 9.90e+07 -.0555556 .0315744 .0024534
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 35 "1992W35" 13529 3.30e+07 9.84e+07  2.49e-08  .040449 .0030457
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 36 "1992W36" 13529 3.30e+07 9.97e+07  .1176471 .0404083 .0218593
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 37 "1992W37" 13529 3.30e+07 1.02e+08 -.0526316 .0235375 .0027893
    77444 "KSRC"  "KENDALL SQUARE RESEARCH CORP"   48878910 1992 38 "1992W38" 13529 3.30e+07 9.95e+07 -.0555556   .05019 .0029741
    end

    Thanks in advance!

  • #2
    With the caveat that I know nothing about -newey-, I can partially answer your first question, based on the characteristics of -runby-.

    1. Can I use the newey-west correction for a regression based on deciles?
    And if so, did I include the command right in the code below?
    A sample of my data is listed at the bottom as an overview (does not work with the code listed below).
    When using -runby-, if you are not getting any results, the first thing to do is re-run it using the -verbose- option. The problem is almost certainly going to be that something is going wrong inside the my_regression program, and the -verbose- option will enable you to see what that is. In this case, when you do that, each output from -runby- gives the following error message:

    Code:
    time variable not set, use -tsset varname ...-
    Now, a limitation of -runby- is that information about -xtset- is lost. The solution is to put another -xtset n_cusip weekly_date- command inside the my_regression program before the -newey- command. When you do that, this problem is resolved. And Stata can now correctly process 3 of the 10 deciles and leave results for you.

    However, for 7 of the deciles, the -newey- command complains about other problems:

    Code:
    weekly_date is not regularly spaced
    and in one case

    Code:
    insufficient observations
    I'm going to guess that in your full data set, the insufficient observations problem will go away. But the weekly_date not being regularly spaced problem, I think, will remain. I think it is related to all of the time gaps in your data, which leads to your various lag variables having missing values, which, in turn, leaves weekly_date irregularly spaced in the estimation sample. I do not know if this is fixable or not. It may be that there is some option to the -newey- command that allows you to run it with irregularly spaced data, or perhaps some alternative command (perhaps user-written) that will do the calculations with irregularly spaced data. Or maybe whatever it is that -newey- computes isn't even meaningful with irregularly spaced data. I really have no idea; I don't even know what -newey- is supposed to do. Hopefully somebody who understands the -newey- command can advise on that.

    Comment


    • #3
      I'm going to guess that in your full data set, the insufficient observations problem will go away. But the weekly_date not being regularly spaced problem, I think, will remain. I think it is related to all of the time gaps in your data, which leads to your various lag variables having missing values, which, in turn, leaves weekly_date irregularly spaced in the estimation sample. I do not know if this is fixable or not. It may be that there is some option to the -newey- command that allows you to run it with irregularly spaced data, or perhaps some alternative command (perhaps user-written) that will do the calculations with irregularly spaced data. Or maybe whatever it is that -newey- computes isn't even meaningful with irregularly spaced data. I really have no idea; I don't even know what -newey- is supposed to do. Hopefully somebody who understands the -newey- command can advise on that.
      Thank you Clyde, for the good overiew of the problem!
      Is someone here an expert on newey-west correction?

      I am greatful for any help!

      Comment


      • #4
        Let me specify my problem:

        I want to use the newey-west correction for my regression which is based on deciles. Can I use it, since I have gaps in my data?
        My data set contains weekly data from CRSP database from 1960-2016 with 14 million observations.

        The quote below is to be found in stata with the code: help newey2
        I am not sure what to make of this. Can the force command sovle my problem or newey2? And if so, are the results statistically useable?
        Or could I construct a linear time series for my observations in sequence? Maybe with tsset?

        Thanks in advance!

        For panel data sets, newey2 computes pooled OLS or 2SLS estimates; it does not implement panel models such as fixed or random effects. newey2 handles missing observations differently for time series and panel data sets. Consider the
        example of a time series data set containing gaps, which is then recast using tsset as a panel data set with one group. newey and newey2 will not run on the time series version without force; with force they treat available
        observations as equally spaced. After the set is cast as a panel, newey2 will run without , force, and will assume zero serial correlation with missing observations.

        Comment


        • #5
          I am with Clyde here in the strong sense that this isn't in my toolbox or area of expertise. Hence I just have a few meta-comments and cannot offer help beyond that.

          You say "in Stata" but newey2 is user-written and the request remains what it ever was, to explain where user-written programs you refer to come from. In this case the user is a user-programmer of very high reputation who does visit the list from time to time.

          Here you've got the right kind of heading to attract interest from econometricians or applied economists who are the most likely people to answer, but patience is required too and answers aren't guaranteed. Statalist works best when there is a very sharp Stata question, but it's capricious otherwise.
          What I shall do next in my project? is the top question for most researchers, but it's not a question that is easy or tempting for others to try to answer.

          No help at all, but I would answer constructively if I could.


          Comment


          • #6
            Nick Cox Thank you! I'll wait and hope for someone from the field to answer.

            Comment


            • #7
              Dear Julian Buchholz,

              I am sorry but I also not an expert in "newey" and therefore cannot give you the answer you are looking for. However, I can ask you a question: why are you running OLS regression by quantiles? The results of these regressions are very difficult to interpret and I am not sure what you can learn form them. Some people do this because they think that this is equivalent to estimating quantile regression, but it is not.

              Best wishes,

              Joao

              Comment


              • #8
                Joao Santos Silva
                Thank you for replying.
                I am running OLS regressions based on deciles and maybe I am expecting something wrong here, but I was hoping to see whether there is a different relationship per decile of the dependent variable and independent variables. I was hoping that I could interprete each like a OLS regression, maybe you could tell me what I am missing here, thank you in advance!

                I used: regress with robust standard errors (permno is the company identifier), the code is attached and the results are at the bottom.


                Code:
                . capture program drop my_regression
                
                . program define my_regression
                  1.     regress week_return lag_turnover_week lag_week_return lag_vola
                > _week, vce(cluster permno)
                  2.     tempname M
                  3.     matrix `M' = r(table)
                  4.     foreach v of varlist lag_turnover_week lag_week_return lag_vol
                > a_week {
                  5.         gen b_`v' = _b[`v']
                  6.         gen se_`v' = _se[`v']
                  7.         gen p_`v' = `M'[4, `=colnumb(`M', "`v'")']
                  8.     }
                  9.     gen rsq = e(r2)
                 10.     gen adj_rsq = e(r2_a)
                 11.     gen n_obs = e(N)
                 12.     exit
                 13. end
                
                . // XTSET THE DATA SO LAGS ARE CALCULATED CORRECTLY
                . xtset n_cusip weekly_date
                       panel variable:  n_cusip (unbalanced)
                        time variable:  weekly_date, 1960w2 to 2016w52, but with gaps
                                delta:  1 week
                
                . gen lag_week_return = L1.week_return
                (157,042 missing values generated)
                
                . gen lag_turnover_week = L1.turnover_week  
                (157,042 missing values generated)
                
                . gen lag_vola_week = L1.week_vola
                (157,668 missing values generated)
                
                .
                . // CREATE DECILES OF TURNOVER FOR EACH WEEK
                . by weekly_date, sort: egen byte decile = xtile(lag_turnover_week), nq
                > (10)
                (157042 missing values generated)
                
                .
                . runby my_regression, by(decile) status
                decile b_lag_turnover_week se_lag_turnover_week p_lag_turnover_week b_lag_week_return se_lag_week_return p_lag_week_return b_lag_vola_week se_lag_vola_week p_lag_vola_week rsq adj_rsq n_obs
                1 1.974207 .0769101 0 .1483803 .0075531 0 -.118184 .0097859 1.84e-33 .017652 .0176499 1384123
                2 .6176248 .028978 0 .0734061 .0056601 2.50e-38 -.1004479 .0092581 2.33e-27 .0057708 .0057686 1382797
                3 .2584684 .0174495 0 .0539037 .0050981 4.52e-26 -.0816299 .0089373 7.13e-20 .0032181 .003216 1383107
                4 .146107 .0122906 1.68e-32 .0416152 .0058778 1.48e-12 -.0317294 .0169253 .06085 .0015568 .0015547 1382782
                5 .0460158 .0087027 1.25e-07 .0242605 .0038051 1.85e-10 -.0267898 .0082859 .0012258 .0005277 .0005255 1382549
                6 .0079393 .0071151 .2645019 .0126564 .0037661 .0007787 .0066119 .0241596 .7843349 .0001446 .0001424 1383514
                7 -.0025437 .0051689 .6226395 .0074271 .0032676 .0230354 .0107809 .0115758 .3516917 .0000671 .0000649 1383125
                8 -.0209334 .004226 7.34e-07 .0010499 .0030216 .728247 .0266943 .0090506 .0031864 .000104 .0001019 1382849
                9 -.0197005 .0027326 5.78e-13 -.0018257 .0037104 .6226801 .04914 .0079009 5.07e-10 .0003149 .0003127 1383160
                10 -.0004249 .0001425 .0028736 .0026919 .0024623 .2742921 .0233229 .006272 .0002008 .0001948 .0001926 1381669

                Comment


                • #9
                  Dear Julian Buchholz,

                  Even if all the observations are generated by the same mechanism, you may get very different results in each "slice" simply due to the endogenous stratification (just like truncation). The following example illustrates my point.

                  Code:
                  clear all
                  set obs 100000
                  set seed 261017
                  g x=rnormal()
                  g y=x+exp(x)*rnormal()
                  qui su y, d
                  local l=r(p10)
                  local u=r(p90)
                  reg y x
                  reg y x if y>`u'
                  reg y x if y<`l'
                  Best wishes,

                  Joao

                  Comment

                  Working...
                  X