Announcement

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

  • Error 301

    After I run the following regression:
    bysort FYEAR SIC: regress TACCATw ATLAGINVw REVATLAGw PPEATLAGw if !missing(TACCATw) & !missing(ATLAGINVw) & !missing(REVATLAGw) & !missing(PPEATLAGw)

    I want to predict the residuals with the following code:
    predict DACC, resid
    However, stata says "last estimates not found r(301):
    "error . . . . . . . . . . . . . . . . . . . . . . . . Return code 301
    last estimates not found;
    You typed an estimation command, such as regress, without
    arguments or attempted to perform a test or typed predict,
    but there were no previous estimation results."

    Does anybody have an idea how this can be fixed? Thank you in advance!

  • #2
    Welcome to Statalist.

    The code you show will use the results from the final regression to make the predictions for all the observations. This is not what you want.

    There are a number of other problems with your code. I think something like the following example is more likely to be what you need.
    Code:
    // set up some example data
    sysuse auto, clear
    drop if missing(rep78)
    
    // run the regressions on the sample data
    levelsof rep78, local(rep)
    levelsof foreign, local(fgn)
    
    generate res = .
    foreach r of local rep {
    foreach f of local fgn {
    capture regress weight length if rep78==`r' & foreign==`f'
    if _rc != 0 display "FAILURE rep78 `r' foreign `f' return code " _rc
    else {
        quietly predict temp, resid
        replace res = temp if rep78==`r' & foreign==`f'
        drop temp
    }
    }
    }
    
    table rep78 foreign, missing contents(n res)
    Code:
    . // set up some example data
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . drop if missing(rep78)
    (5 observations deleted)
    
    . 
    . // run the regressions on the sample data
    . levelsof rep78, local(rep)
    1 2 3 4 5
    
    . levelsof foreign, local(fgn)
    0 1
    
    . 
    . generate res = .
    (69 missing values generated)
    
    . foreach r of local rep {
      2. foreach f of local fgn {
      3. capture regress weight length if rep78==`r' & foreign==`f'
      4. if _rc != 0 display "FAILURE rep78 `r' foreign `f' return code " _rc
      5. else {
      6.     quietly predict temp, resid
      7.     replace res = temp if rep78==`r' & foreign==`f'
      8.     drop temp
      9. }
     10. }
     11. }
    (2 real changes made)
    FAILURE rep78 1 foreign 1 return code 2000
    (8 real changes made)
    FAILURE rep78 2 foreign 1 return code 2000
    (27 real changes made)
    (3 real changes made)
    (9 real changes made)
    (9 real changes made)
    (2 real changes made)
    (9 real changes made)
    
    . 
    . table rep78 foreign, missing contents(n res)
    
    ------------------------------
    Repair    |
    Record    |      Car type     
    1978      | Domestic   Foreign
    ----------+-------------------
            1 |        2         .
            2 |        8         .
            3 |       27         3
            4 |        9         9
            5 |        2         9
    ------------------------------

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X