Announcement

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

  • r(2000) no observations using foreach and forvalue

    Hi,

    I try to run a tobit regression on the panel dataset through the following code. However, it does not successfully skip error of
    Code:
     insufficient observations r(2000);
    Can you give me some suggestions? I have attached a sample of my data for testing the code. Many thanks.


    Code:
    local depent  pat cite exi6 exr6
     
    foreach dep of local depent{
         forvalues i= 1(1)10{
    
             tobit head1`dep'  time_treat PPETA LEV CAPEXTA Q LN_AGE SHORT_LIQ ROA RDTA  i.year i.firm_id if industry==`i' & diff!=0 & 1990<=year<=2014  ,ll(0) vce(cluster year)
            
            if c(rc)==0{
            eststo ols_`dep'_`i'_con1
            }
           else if inlist(c(rc), 2000, 2001)  {  
            //  NO OBSERVATIONS OR INSUFFICIENT OBSERVATIONS
            //  ADVISE USER OF THE SITUATIOIN, BUT AS THIS IS
            //  AN EXPECTED PROBLEM, MOVE ON
                display as error "industry=='i' : no or insufficient observations"
                
               }
           else {  
            display as error "Unexpected error when industry == `i' "
            error c(rc)
            }
        }
    }
    Attached Files

  • #2
    Your code throws you out before the if ... else ... commands are seen, let alone executed. Stata does not hold on to see what is coming next.

    Here is a simplified if silly analogue


    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . regress mpg weight if 7 > 42
    no observations
    r(2000);
    
    . noisily capture regress mpg weight if 7 > 42
    
    . if _rc == 2000 di "no observations"
    no observations
    Sometimes noisily capture is what you need and sometimes capture noisily and sometimes capture.

    Note: You're asked not to post .dta attachments. https://www.statalist.org/forums/help#stata

    Comment

    Working...
    X