Announcement

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

  • observation limitation

    Hi,

    I have some problem with stata code.

    I need to make modified jones model by industry and year.
    In my code, there needs a limitation for more than 10 observations in each year x industry for regression.
    Does Stata provide any command for the regressions to be run with a minimum of 10 observations?
    I think maybe there needs some other code in line with bold

    by fyr ind_code: gen total=_N

    vallist ind_code
    local a=r(list)
    vallist fyr
    local b=r(list)
    foreach i in `a' {
    foreach x in `b' {
    if total>10 capture noisily reg total_acc inv_ta rev_ar s_ppe if ind_code==`i'&fyr==`x',nocons
    capture noisily predict aa2,resid
    capture noisily replace aa=aa2 if if ind_code==`i'&fyr==`x'
    capture noisily drop aa2
    }
    }
    Last edited by Ashley Choi; 06 Jun 2018, 03:04.

  • #2
    vallist (STB, as you are asked to explain) is long since superseded by official command levelsof.

    Here's a version of your code that avoids it any way:

    Code:
    egen group = group(ind_code fyr)
    gen aa = .
    su group, meanonly
    
    quietly forval g = 1/`r(max)' {
        count if !missing(total_acc, inv_ta, rev_ar, s_ppe) & group == `g'
        if r(N) > 10 {
            reg total_acc inv_ta rev_ar s_ppe if group == `g', nocons
            predict aa2, resid
            replace aa = aa2 if group == `g'
            drop aa2
        }
    }

    Comment

    Working...
    X