Announcement

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

  • reg3 - r(2001) Insufficient observations error

    Dear Statalists,

    I try to run a system of two simultaneous equations imposed on Monte Carlo generated data using the 3sls method. The problem is, while I have set the number of observations at 50000000, the simulation stops with error message of: "insufficient observations - an error occurred when simulate executed my3sls".

    I would appreciate if some one could help me with this. The code is:


    #delimit ;
    clear all ;
    set seed 10101 ;

    * Set the values of the parameters

    global numobs = 50000000 ; /*numobs = sample size*/
    global numsims = 2000 ;/*numsims = replication number*/

    scalar beta12 = 1.5 ;
    scalar beta21 = 1.8 ;
    scalar gamma11 = 1.5 ;
    scalar gamma12 = 0.5 ;
    scalar gamma21 = 1 ;
    scalar gamma32 = 2 ;

    capture program drop my3sls ;
    program my3sls, rclass ;
    version 13 ;
    drop _all ;
    set obs $numobs ;
    tempvar x1 x2 x3 eps1 eps2 u1 u2 y1 y2 ;

    generate `y1' =. ;/* initiate y -- all missing values */
    generate `y2' =. ;/* initiate y -- all missing values */

    generate `x1' = runiform() ;
    generate `x2' = runiform() ;
    generate `x3' = runiform() ;

    generate `eps1' = rnormal() ;
    generate `eps2' = rnormal() ;

    generate `u1' = 1.708*`eps1' + 1.404*`eps2' ;
    generate `u2' = 1.732*`eps2' ;

    replace `y1' = (beta21)*(`y2') + (gamma11)*(`x1') + (gamma21)*(`x2') + `u1' ;
    replace `y2' = (beta12)*(`y1') + (gamma12)*(`x1') + (gamma32)*(`x3') + `u2' ;

    reg3 (`y1' = `y2' `x1' `x2') (`y2' = `y1' `x1' `x3') ;

    return scalar b1 = _b[`x1'] ;
    return scalar b2 = _b[`x2'] ;
    return scalar b3 = _b[`x3'] ;

    end ;

    simulate b1=r(b1) b2=r(b2) b3=r(b3), reps($numsims) saving(results, replace) nolegend nodots: my3sls ;

    use results, clear ;
    summarize ;




    Thanks in advance,
    Homa
    Attached Files

  • #2
    Your problem is in the replace `y#' statement. You've created variables y1 and y2 that are missing. You then multiply by and add to those missing values. Stata will return a missing value. So all your observations in y1 and y2 are missing. See a very simplified example below.



    Code:
    clear
    set obs 10
    gen y1=.
    gen y2=.
    replace y1=y2*10+5
    
    sum y1
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      It is often a useful technique to simplify the code to narrow down the possibilities. I eliminated the simulation and the my3sls program and just ran one instance of your reg3 command.
      Code:
      clear all
      
      * Set the values of the parameters
      global numobs = 50000000    /*numobs = sample size*/
      
      
      scalar beta12 = 1.5
      scalar beta21 = 1.8
      scalar gamma11 = 1.5
      scalar gamma12 = 0.5
      scalar gamma21 = 1
      scalar gamma32 = 2
      scalar alpha= 0.05
      
      set obs $numobs
      tempvar x1 x2 x3 eps1 eps2 u1 u2 y1 y2
      
      generate `y1' =. /* initiate y -- all missing values */
      generate `y2' =. /* initiate y -- all missing values */
      
      generate `x1' = runiform()
      generate `x2' = runiform()
      generate `x3' = runiform()
      
      generate `eps1' = rnormal()
      generate `eps2' = rnormal()
      
      generate `u1' = 1.708*`eps1' + 1.404*`eps2'  
      generate `u2' = 1.732*`eps2'
      
      replace `y1' = (beta21)*(`y2') + (gamma11)*(`x1') + (gamma21)*(`x2') + `u1'
      replace `y2' = (beta12)*(`y1') + (gamma12)*(`x1') + (gamma32)*(`x3') + `u2'
      
      reg3 (`y1' = `y2' `x1' `x2') (`y2' = `y1' `x1' `x3')  
      
      return scalar b1 = _b[`x1']
      return scalar b2 = _b[`x2']
      return scalar b3 = _b[`x3']
      This was the result.
      Code:
      . clear all
      
      .
      . * Set the values of the parameters
      . global numobs = 50000000    /*numobs = sample size*/
      
      .
      .
      . scalar beta12 = 1.5
      
      . scalar beta21 = 1.8
      
      . scalar gamma11 = 1.5
      
      . scalar gamma12 = 0.5
      
      . scalar gamma21 = 1
      
      . scalar gamma32 = 2
      
      . scalar alpha= 0.05
      
      .
      . set obs $numobs
      number of observations (_N) was 0, now 50,000,000
      
      . tempvar x1 x2 x3 eps1 eps2 u1 u2 y1 y2
      
      .
      . generate `y1' =. /* initiate y -- all missing values */
      (50,000,000 missing values generated)
      
      . generate `y2' =. /* initiate y -- all missing values */
      (50,000,000 missing values generated)
      
      .
      . generate `x1' = runiform()
      
      . generate `x2' = runiform()
      
      . generate `x3' = runiform()
      
      .
      . generate `eps1' = rnormal()
      
      . generate `eps2' = rnormal()
      
      .
      . generate `u1' = 1.708*`eps1' + 1.404*`eps2'  
      
      . generate `u2' = 1.732*`eps2'
      
      .
      . replace `y1' = (beta21)*(`y2') + (gamma11)*(`x1') + (gamma21)*(`x2') + `u1'
      (0 real changes made)
      
      . replace `y2' = (beta12)*(`y1') + (gamma12)*(`x1') + (gamma32)*(`x3') + `u2'
      (0 real changes made)
      
      .
      . reg3 (`y1' = `y2' `x1' `x2') (`y2' = `y1' `x1' `x3')  
      no observations
      r(2000);
      We immediately note that the two replace commands apparently did not have the desired effect. That should not have surprised us, because the first replace command has all missing values for y2 so the results will all be missing, and similarly for the second replace command. It will surprise those of us who have read Carole's post immediately preceding, which this one crossed in cyberspace.

      Without going through the messy algebra here, I think you are going to have to substitute your expression for y2 into your expression for y1, then expand and simplify, to give you an expression for y1 that only involves the assumed values of the betas, gammas, and x's. Once you've done that, the current expression for y2 should work unchanged. I think.
      Last edited by William Lisowski; 19 Mar 2016, 11:12.

      Comment


      • #4
        Thank you Mr. Lisowski

        Comment

        Working...
        X