Announcement

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

  • How do i include the results of a no observations regression into a matrix?

    So my problem is that i have a dataset of 502 firms but some of them have no observations.
    The thing is, i want to include these results into my matrix because otherwise the coefficients, p-values and adjusted R2 are shifted so that the firms don“t have the right values standing next to them in the matrix.
    My code is like that:


    set matsize 510

    unab y : TOYOTAMOTORTOTRETURNIND-COMMUTUREDEADDELIST280910

    local l : word count `y'

    matrix p = J(`l',3,.)
    matrix rownames p = `y'
    matrix colnames p = "adjR2" "coef" "p"

    matlist p

    local i = 1
    foreach var of local y {
    {
    capture noisily reg `var' RenditenTopix PercentageChangeTWEXR if `var'>-1000, robust
    if c(rc) ==0 {
    matrix p[`i++',1] = (1-(1-e(r2))*(e(df_r)+e(df_m))/(e(df_r))), _b[PercentageChangeTWEXR], 2*ttail(e(df_r), abs(_b[PercentageChangeTWEXR]/_se[PercentageChangeTWEXR]))
    }
    else if c(rc) !=2000{
    exit (c(rc))
    }
    }
    }

    matlist p


    So thank you very much for your help in advance!

  • #2
    Your code is hard to read presented like that. Please note FAQ Advice #12 on using CODE delimiters.

    Code:
    set matsize 511
    
    unab y : TOYOTAMOTORTOTRETURNIND-COMMUTUREDEADDELIST280910
    
    local wc : word count `y'
    
    matrix p = J(`wc',3,.)
    matrix rownames p = `y'
    matrix colnames p = "adjR2" "coef" "p"
    
    matlist p
    
    local i = 1
    foreach var of local y {
          capture noisily reg `var' RenditenTopix PercentageChangeTWEXR if `var'>-1000, robust
          if c(rc) ==0 {
               matrix p[`i',1] = (1-(1-e(r2))*(e(df_r)+e(df_m))/(e(df_r))), _b[PercentageChangeTWEXR], 2*ttail(e(df_r), abs(_b[PercentageChangeTWEXR]/_se[PercentageChangeTWEXR]))
          }
          local ++i
    }
    
    matlist p
    Notes: I would never use l (letter l) as a macro name. it's too close to 1 (number one), which sometimes is a reasonable macro name.

    More crucially, you are incrementing your counter if and only if there was a regression that worked. Is that really what you want? See above for what I would imagine is closer to what you want.

    What's the cut-off > -1000 about? If there is some code for missings say -9999 better to use mvdecode first.
    Last edited by Nick Cox; 21 May 2019, 09:36.

    Comment


    • #3
      Code:
      help mvdecode 

      Comment

      Working...
      X