Announcement

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

  • Issue with simulations data - non r-class program may not set r()

    I have written a program which does not output my values correctly
    Code:
    program Datageneration, rclass
    matrix my = (2\2\2)
    matrix cov = (3,1.25,0.75\1.25,1,0.6\0.75,0.6,1)
    drawnorm x1 x2 x3, n(200) means(my) cov(cov)
    gen y=x1
    regress y x1
    return scalar b1=_b[x]
    end
    which returns "non r-class program may not set r()".

    Where in my programming have I gone wrong?

  • #2
    Works fine for me:

    Code:
    . clear all
    
    .
    . program Datageneration, rclass
      1. matrix my = (2\2\2)
      2. matrix cov = (3,1.25,0.75\1.25,1,0.6\0.75,0.6,1)
      3. drawnorm x1 x2 x3, n(200) means(my) cov(cov)
      4. gen y=x1
      5. regress y x1
      6. return scalar b1=_b[x]
      7. end
    
    .
    . Datageneration
    (obs 200)
    
          Source |       SS           df       MS      Number of obs   =       200
    -------------+----------------------------------   F(1, 198)       =         .
           Model |   563.58089         1   563.58089   Prob > F        =         .
        Residual |           0       198           0   R-squared       =    1.0000
    -------------+----------------------------------   Adj R-squared   =    1.0000
           Total |   563.58089       199  2.83206478   Root MSE        =         0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |          1          .        .       .            .           .
           _cons |          0  (omitted)
    ------------------------------------------------------------------------------
    
    .
    end of do-file
    
    . return list
    
    scalars:
                     r(b1) =  1
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hmm. Thats weird. When I run the data generating process then it retuns this:
      Be aware that I have set a seed as to easier compare results.
      Code:
      . clear all
      
      . set seed 1
      
      .
      . matrix my = (2\2\2)
      
      . matrix cov = (3,1.25,0.75\1.25,1,0.6\0.75,0.6,1)
      
      . drawnorm x1 x2 x3, n(200) means(my) cov(cov)
      (obs 200)
      
      . gen y=x1
      
      . regress y x1
      
            Source |       SS           df       MS      Number of obs   =       200
      -------------+----------------------------------   F(1, 198)       =         .
             Model |  576.942035         1  576.942035   Prob > F        =         .
          Residual |           0       198           0   R-squared       =    1.0000
      -------------+----------------------------------   Adj R-squared   =    1.0000
             Total |  576.942035       199  2.89920621   Root MSE        =         0
      
      ------------------------------------------------------------------------------
                 y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                x1 |          1          .        .       .            .           .
             _cons |  -4.44e-16          .        .       .            .           .
      ------------------------------------------------------------------------------
      
      . return scalar b1=_b[x]
      non r-class program may not set r()
      
      
      . return list
      
      scalars:
                    r(level) =  95
      
      matrices:
                    r(table) :  9 x 2
      
      .
      
      
      
      end of do-file

      Comment


      • #4
        Hi Barc
        The difference between what you did and what Marteen did is that he run the code from the dofile editor , all at once.
        You instead are trying to do it line by line. So the line, return scalar, is not reunning within an rclass program.
        Fernando

        Comment


        • #5
          you did not include the lines:

          program Datageneration, rclass

          and

          end

          in your example. Now the error message makes sense: If you are not in a program, than that non-existing program obviously cannot return anything.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Hey Fernando and Maarten

            I feel very stupid right now, as I have been sitting with this for a couple of hours... Thank you very much both, and have a great day.

            Comment

            Working...
            X