Announcement

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

  • Problem with statsby-collecting number of observations in cross sectional regression

    Please help out. I would like to collect the number of observations(N) in a regression for each quarter in addition to coefficients, se and r squared. My data is panel data. Here is my code
    I use N as number of observations but it does not generate anything other than missing observations. However, am able to generate coefficients, se and r squared if i remove n=r(N)

    Code:
    *drop unwanted variables
    keep qdate ticker delta_kt
    
    *sort data
    sort qdate ticker
    
    *Create lag variable
    egen id = group(ticker)
    xtset id qdate
    generate delta_kt_1 = L.delta_kt 
    
    *Cross-sectional regressions
    sort qdate
    statsby beta=_b[delta_kt_1] beta_se=_se[delta_kt_1] rsq=e(r2) n=r(N), by(qdate) clear: reg delta_kt delta_kt_1, noconstant
    format qdate %tq
    drop if beta==.
    Here is my sample data with dataex

    Code:
    *example generated by -dataex-. To install: ssc install dataex
    clear
    
    ticker    qdate    delta_kt
    ST    2008q2    1.088697
    FM    2008q2    .0505587
    NIT    2008q2    1.088697
    PC    2008q2    -.7651212
    MP    2008q2    -.2089759
    ILL    2008q2    -.2089759
    SUN    2008q2    1.088697
    NB    2008q2    -.2089759
    NIC    2008q2    -1.506648
    PI    2008q2    -1.506648
    NM    2008q2    1.088697
    NIC    2008q3    1.147993
    ILL    2008q3    -1.506082
    NM    2008q3    -.8425636
    FM    2008q3    .1527145
    ST    2008q3    .1527145
    MP    2008q3    1.147993
    PC    2008q3    -.5581983
    NB    2008q3    -.8425636
    NIT    2008q3    1.147993
    FM    2008q4    -.3804566
    NB    2008q4    .6419926
    ST    2008q4    -.7480035
    NIC    2008q4    -.5127734
    MP    2008q4    -.1599282
    TM    2008q4    -1.509042
    ILL    2008q4    -.3804566
    NM    2008q4    -.1599282
    NIT    2008q4    1.604298
    PC    2008q4    1.604298
    ILL    2009q1    .9427915
    TM    2009q1    -.8208599
    RE    2009q1    .9427915
    ST    2009q1    -1.114802
    FM    2009q1    -1.526321
    NIC    2009q1    .9427915
    NB    2009q1    -.4289374
    PC    2009q1    .1197541
    NM    2009q1    .9427915
    NIC    2009q2    -.4951594
    NM    2009q2    -.661042

  • #2
    regress stores the number of observations as e(N).

    Comment


    • #3
      Many thanks Andrew Musau

      Comment


      • #4
        Many thanks Andrew Musau . This has been very helpful to me.

        Comment

        Working...
        X