Announcement

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

  • Cross sectional regression by year and sized-based peer groups

    Firstly, Happy Holidays to everyone

    Now my problem. I need to run a cross-sectional regression by year and by size-based peer groups. Size-based peer groups are chosen by matching the year and the 50 adjacent observations (25 firms with a lower value of total assets and 25 firms with a higher value of total assets.
    Can anyone please suggest how I can generate those peer groups and run the regression?
    I am using Stata 14.2

    Thank you.
    Last edited by Ivana Rozic; 24 Dec 2019, 13:52.

  • #2
    In queries like this one, you would get a more relevant and accurate answer if you post an example dataset. I have not fully understood the description of size-based groups. Usually, portfolios or groups are based on quartiles or percentiles, not on an absolute number. Therefore, if you want to create two groups of firms in each year, then something like the following will work:

    * For creating two groups of firms in each year, I am using astile. More on astile here
    [CODE]
    ssc install astile, replace

    * Download example data

    webuse grunfeld, clear

    * Create two groups based on mvalue
    bys year: astile size = mvalue, nq(2)

    [CODE]

    * Cross-sectional regression
    * For Cross-sectional regression, install asreg, more on asreg here

    Code:
    ssc install asreg, replace
    
    * Yearly cross-sectional regression for each size group
    bys size year: asreg  invest mvalue kstock
    
    * Show some results on the screen
    sort size year
    bys size year: keep if _n == _N
    list _* in 1/4
    
    
         +---------------------------------------------------------------------+
         | _Nobs         _R2      _adjR2    _b_mvalue   _b_kstock      _b_cons |
         |---------------------------------------------------------------------|
      1. |     5   .97562758   .95125516    .11685979   .15206316   -6.6686201 |
      2. |     5   .54387973   .08775947   -.01622041   .14669198    12.808744 |
      3. |     5   .76141341   .52282681   -.06422692   .25370151    16.438594 |
      4. |     5   .66237783   .32475567     .0187906   .12439183    6.7587034 |
         +---------------------------------------------------------------------+
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Thank you for the reply, but this is not what I am looking for. So I am looking to form groups with the 50 nearest neighbors observations of l_A.

      For the reference, I am trying to follow Ecker et al. (2013) JAE, Estimation sample selection for discretionary accruals models.

      And to cite them p.194:
      2. Foreach event-firm-year, we select initial peer firms from which estimation samples will be chosen:
      c. Size - based peer groups (total assets, lagged total assets etc. chosen by matching the year and the 25adjacent (to the event firm)lower-ranked firms and the 25 adjacent (to the event firm) higher-ranked firms; these are the event firm's “closest neighbors.”

      As I've understood, I need to make peer groups and then estimate discretionary accruals.

      So basically I want to run regression by year and size-based peer groups rather than industries.

      This is an example of my data.


      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int year float(id l_A X0 X1 X2 X3)
      2018  1  36431  .00002744915   .001454805 .00013724575   2.545646e-06
      2009  2  19773  .00005057401    -.1944065    .08380114   6.176647e-07
      2010  2  16294  .00006137229   -.06364306    .08119553  1.6028657e-06
      2011  2  16158 .000061888844    .17786855    .08243594  3.2428004e-06
      2012  2  19085  .00005239717   .031805083     .0611999  1.2215963e-06
      2013  2  19130  .00005227391    .09529535    .08489284  4.0001245e-07
      2014  2  21693  .00004609782    .16553727    .07693726   4.300569e-07
      2015  2  23689  .00004221369   .030520495     .0903795  1.2662628e-06
      2016  2  22836  .00004379051  -.016246278    .10391487   1.364458e-06
      2017  2  20893  .00004786292    .01325803    .13124013  -4.078995e-08
      2018  2  23468  .00004261122   -.07282256    .10763593 -2.7778815e-06
      2006  3  38084 .000026257747   -.25706333    .22623675  2.0823177e-06
      2007  3  39368  .00002540134     .3118777      .185506  2.1874007e-06
      2008  3  46938   .0000213047     .1346457    .06521369  2.0716466e-06
      2009  3  42339 .000023618886    -.2068542   .017903116 -1.3337377e-06
      2010  3  40075 .000024953213    .08878353   .015121647   5.354278e-06
      2011  3  47294  .00002114433    .10455872   .012242568    7.45646e-07
      2012  3  54559  .00001832878    .09254202    .01070401   9.991668e-07
      2013  3  59820 .000016716816    .09998328   .009010364  2.1954884e-06
      2014  3  60190 .000016614056    -.2307526   .006263499   1.256555e-07
      2015  3  60953 .000016406084    -.3307138    .00787492  -7.218041e-07
      2016  3  66074 .000015134546    .06164301    .00482792  -9.118306e-06
      2017  3  42207  .00002369275   -.01990191  .0028431304  -6.244231e-06
      2018  3  17841  .00005605067   -1.4898268   .004259851 -.000019751136
      2006  4  67173 .000014886934    .05539428     .5424352   5.321123e-07
      2007  4  63396 .000015773865    .03654805     .5444981  -2.485807e-06
      2008  4  66197 .000015106425  .0041391603    .48849645  1.1489168e-06
      2009  4  70081 .000014269202   .017308543    .46005335  1.3638075e-06
      2010  4  73909 .000013530152   .005263229     .4168099   9.215327e-07
      2011  4  81457 .000012276416    .03620315     .3645113   1.222978e-06
      2012  4  90815 .000011011397    .01450201     .3122502   9.117055e-07
      2013  4  96405 .000010372906   .008547274    .28700793  1.1831273e-06
      2014  4  51254 .000019510673    .09753385    .56225854    3.67676e-06
      2015  4  51717    .000019336    .05845273     .5466481   3.183135e-06
      2016  4  62282 .000016056003    .02800167     .4935615   3.685818e-06
      2017  4  75771  .00001319766   .012234232     .4648876   2.446491e-06
      2018  4  75901 .000013175057     .0341234     .6048273  1.9400672e-06
      2006  5  13257  .00007543185    .09006563     .6041337   9.636898e-06
      2007  5  12970    .000077101  -.007632999    .58558214   4.113082e-06
      2008  5  11997  .00008335417    -.1897141     .5812286   -6.36264e-06
      2009  5  11594   .0000862515   -.10979817    .51811284 -2.8440195e-06
      2010  5  10099   .0000990197  -.014555897    .51133776  -8.073931e-06
      2011  5   9333  .00010714668   -.07382406     .4513018 -4.1257917e-06
      2012  5   8648  .00011563367   -.06544866     .3959297   2.659604e-07
      2013  5   7826   .0001277792    .06644518     .3577818  -7.257714e-06
      2014  5   7060  .00014164306   -.03427762    .31133145  -4.501957e-06
      2015  5   7142   .0001400168    -.0817698    .23354803 -.000016087213
      2016  5   6754   .0001480604   -.13206989     .1473201 -.000032776064
      2017  5   5082   .0001967729   -.21054703    .09071232  -.00011860677
      2006  6 415100  2.409058e-06  -.029631414   .013008914   6.520494e-08
      2007  6 410100 2.4384296e-06 .00024384297    .01316752  -2.541291e-08
      2008  6 403000 2.4813896e-06    .02332506    .01414392   1.844678e-08
      2009  6 417000 2.3980815e-06  -.016786572   .014148681   6.570025e-07
      2010  6 541300 1.8474044e-06    .00831332   .010345465   2.910834e-07
      2011  6 492500  2.030457e-06   -.01502538   .010964467  -2.239932e-08
      2012  6 489500 2.0429009e-06   .005924413   .010623084 -1.5099045e-09
      2013  6 405900  2.463661e-06  .0019709289    .01207194  -2.135417e-08
      2014  6 403800 2.4764736e-06   -.01015354   .011391778  -4.878355e-06
      2016  6 137200   7.28863e-06   .025510205   .029883383 -1.8917856e-07
      2017  6 138700  7.209806e-06  .0021629415    .02451334   1.572704e-06
      2006  7  68016 .000014702423    .09009645     .3550635  1.1430092e-06
      2007  7  69151 .000014461107    .05059941     .3664155 -1.4474854e-07
      2008  7  73630  .00001358142    .08247997     .3401331  -2.265105e-06
      2009  7  66363 .000015068637    .03152359     .3426458   7.901072e-07
      2010  7  58836 .000016996397    -.0702631     .3617003    8.41229e-07
      2011  7  58067 .000017221486    .05476432     .3577075   1.893522e-06
      2012  7  64274 .000015558391  .0006690108     .3638485    5.72834e-06
      2013  7  94089 .000010628235    .06322737    .27518627   9.756325e-07
      2017  7 109590   9.12492e-06   .028998997     .1338352  2.4284694e-07
      2018  7 110545   9.04609e-06    .06599122     .1372925  1.0781356e-07
      2010  8   3482  .00028719127    -.1550833     .3256749  .000011477813
      2011  8   3503   .0002854696     .0882101     .3277191   .00001373677
      2012  8   3803   .0002629503   -.05101236     .3058112     8.1562e-06
      2006  9  37351 .000026773045   -.05732109    .34082085   6.931306e-07
      2007  9  38240  .00002615063  -.035878662     .3381276  1.4882306e-06
      2008  9  38886 .000025716196     .2940647     .3407139   6.858796e-07
      2009  9  38956 .000025669986   -.06432898     .3877708   8.251068e-07
      2010  9  41160  .00002429543   .016569484     .3525996  1.2890704e-06
      2011  9  44913  .00002226527    .11813951     .3121591  1.1886982e-06
      2012  9  46827   .0000213552   -.14214022     .3435411   1.627809e-07
      2013  9  49065 .000020381127   -.04008968     .3480485   3.852758e-07
      2006 10  84705  .00001180568   .005702143    .45455405  -6.827348e-07
      2007 10  78176  .00001279165   -.16552395    .46638355    9.34158e-08
      2008 10  87089 .000011482506   -.04130258     .3830794  -2.148284e-06
      2009 10  50387  .00001984639    -.5169587     .6054141 -1.9963825e-06
      2011 10  88582 .000011288975     .7222912     .4559956   5.317784e-07
      2012 10 115463  8.660783e-06    .15199675     .3387406   5.354714e-07
      2013 10 110534   9.04699e-06   -.05384769      .346563   7.916599e-07
      2014 10 110199 9.0744925e-06     .2574978     .4562383   7.133396e-07
      2015 10 139729   7.15671e-06   -.08806332    .44204855   3.241784e-07
      2016 10 172086  5.811048e-06    .14067966     .3317004  5.6169415e-07
      2010 11  26436   .0000378272   -.26804358     .6289151  1.9505717e-06
      2011 11  27790 .000035984165   .020942785     .5332854  2.0690618e-06
      2012 11  29183 .000034266526     .1852791     .5759175   2.164351e-06
      2013 11  28973 .000034514895    .04507645     .5681842  -2.214036e-07
      2014 11  28684  .00003486264     .0794171     .6270395  -3.232512e-07
      2015 11  30198 .000033114775  -.024571164     .7383602   1.486064e-06
      2016 11  36701 .000027247213   .023023896     .6859214  1.6819656e-06
      2017 11  43334 .000023076567    .09101398    .57578343    1.80883e-06
      2018 11  44550  .00002244669   .032794613     .7080584  2.0174825e-06
      end
      format %ty year
      ------------------ copy up to and including the previous line ------------------

      Comment


      • #4
        Please can someone confirm if this code #4 s https://www.statalist.org/forums/for...ulate-the-mean
        could be implemented in the regression loop below without generating peer variables but looping over peer instead of g_industry?


        Code:
        gen MDJ_TAiy=.
        forval y = 2006(1)2017{
        forval i = 1(1)7{
        display `i'
        display `y'
        reg $ylist $xlistMJ if `i'== g_industr &`y'== year
        predict r if `i'== g_industr &`y'== year, resid
        replace MDJ_TAiy =r if `i'== g_industr &`y'== year
        drop r
         
        }
        }
        Many thanks.
        Last edited by Ivana Rozic; 29 Dec 2019, 21:35.

        Comment


        • #5
          I am not sure about your question. On a side note, I may point out that this whole code can be reduced to one line using asreg
          Code:
           
           bys g_industr year: asreg $ylist $xlistMJ, fit
          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment


          • #6
            Thank you.

            Comment

            Working...
            X