Announcement

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

  • Help regarding missing values....

    Hi,

    I have the following code...When I run it it returns the following:
    Click image for larger version

Name:	Skærmbillede 2022-03-15 132208.png
Views:	1
Size:	23.3 KB
ID:	1654434


    And it just keeps running...

    //a)

    clear all

    set seed 1234567
    set obs 100

    gen t = _n -1
    tsset t

    gen epsilon = rnormal()
    gen yt = 0
    replace yt = epsilon + L.yt if _n > 1

    generate model = yt - L.yt
    regress model L.yt

    drop yt

    //b)

    //Prepare Matrix:
    matrix rhot = J(10000,2,.)

    //Loop:
    forvalues i = 1/10000 {

    gen epsilon`i' = rnormal()
    gen yt`i' = 0
    replace yt`i' = epsilon`i' + L.yt`i' if _n > 1

    generate model`i' = yt`i' - L.yt`i'

    quietly regress model`i' L.yt`i'
    matrix saveresults = r(table)
    scalar row=`i'
    matrix rhot[row,1]= saveresults[1,1]
    matrix rhot[row,2]= saveresults[3,1]

    drop yt`i'
    drop epsilon`i'
    drop model`i'

    }



    //Histograms
    histogram rho_regr
    histogram t_regr

    //Percentiles
    _pctile t_regr, p(5)
    return list


    //c)

    //Prepare Matrix:
    matrix rhot2 = J(10000,4,.)

    //Loop:
    forvalues i = 1/10000 {

    gen epsilon`i' = rnormal()
    gen yt`i' = 0
    replace yt`i' = 0.5 + epsilon`i' + L.yt`i' if _n > 1

    generate model`i' = yt`i' - L.yt`i'

    quietly mvreg model`i' = L.yt`i' t
    matrix saveresults = r(table)
    scalar row=`i'
    matrix rhot2[row,1]= saveresults[1,3] // alpha
    matrix rhot2[row,2]= saveresults[1,2] // beta
    matrix rhot2[row,3]= saveresults[1,1] // rho
    matrix rhot2[row,4]= saveresults[3,1] // rho's t

    drop yt`i'
    drop epsilon`i'
    drop model`i'
    }

    svmat rhot2, names( col )
    rename c1 alpha
    rename c2 beta
    rename c3 rho
    rename c4 rho_t

    //Histograms
    histogram rho
    histogram rho_t

    //Percentiles
    _pctile rho_t, p(5)
    return list


    //d)

    //Prepare Matrix:
    matrix rhot3 = J(10000,1,.)

    //Loop:
    forvalues i = 1/10000 {

    gen epsilon`i' = rnormal()
    gen yt`i' = 0
    replace yt`i' = 0.5 + epsilon`i' + L.yt`i' if _n > 1

    generate model`i' = yt`i' - L.yt`i'

    quietly regress model`i' L.yt`i', noconstant
    matrix saveresults = r(table)
    scalar row=`i'
    matrix rhot3[row,1]= saveresults[3,1] // rho's t

    drop yt`i'
    drop epsilon`i'
    drop model`i'
    }

    svmat rhot3, names( col )
    rename c1 rho_t

    //Percentiles
    _pctile rho_t, p(5)
    return list

  • #2
    You can suppress the messages from the replace command by using the quietly prefix on it as you did on your regress commands. Then I would suggest changing 10000 to 10 and seeing if the smaller test runs successfully before spending time waiting for 10000 iterations on each of your loops to complete.

    Comment


    • #3
      With 10 it returns this:

      clear all

      .
      . set seed 1234567

      . set obs 100
      Number of observations (_N) was 0, now 100.

      .
      . gen t = _n -1

      . tsset t

      Time variable: t, 0 to 99
      Delta: 1 unit

      .
      . gen epsilon = rnormal()

      . gen yt = 0

      . replace yt = epsilon + L.yt if _n > 1
      (99 real changes made)

      .
      . generate model = yt - L.yt
      (1 missing value generated)

      . regress model L.yt

      Source | SS df MS Number of obs = 99
      -------------+---------------------------------- F(1, 97) = 1.49
      Model | 1.49484416 1 1.49484416 Prob > F = 0.2259
      Residual | 97.6292336 97 1.00648694 R-squared = 0.0151
      -------------+---------------------------------- Adj R-squared = 0.0049
      Total | 99.1240777 98 1.01147018 Root MSE = 1.0032

      ------------------------------------------------------------------------------
      model | Coefficient Std. err. t P>|t| [95% conf. interval]
      -------------+----------------------------------------------------------------
      yt |
      L1. | -.0219611 .0180202 -1.22 0.226 -.0577263 .0138041
      |
      _cons | -.3191688 .1785639 -1.79 0.077 -.6735687 .0352311
      ------------------------------------------------------------------------------

      .
      . drop yt

      .
      . //b)
      .
      . //Prepare Matrix:
      . matrix rhot = J(10,2,.)

      .
      . //Loop:
      . forvalues i = 1/10 {
      2.
      . gen epsilon`i' = rnormal()
      3. gen yt`i' = 0
      4. quietly replace yt`i' = epsilon`i' + L.yt`i' if _n > 1
      5.
      . generate model`i' = yt`i' - L.yt`i'
      6.
      . quietly regress model`i' L.yt`i'
      7. matrix saveresults = r(table)
      8. scalar row=`i'
      9. matrix rhot[row,1]= saveresults[1,1]
      10. matrix rhot[row,2]= saveresults[3,1]
      11.
      . drop yt`i'
      12. drop epsilon`i'
      13. drop model`i'
      14.
      . }
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)
      (1 missing value generated)

      .
      .
      .
      . //Histograms
      . histogram rho_regr
      variable rho_regr not found
      r(111);

      end of do-file

      r(111);

      .

      Comment


      • #4
        Don't get why my code doesn't return the histograms as well...

        Comment


        • #5
          #3 asks for a histogram of a variable that doesn't exist. Nowhere in the code is rho_regr created.

          Comment


          • #6
            Note also that you still have messages coming out of your loop. Unless you want eventually to see
            Code:
            (1 missing value generated)
            10000 times, you will want to add quietly in front of the generate command that follows the replace command.

            Comment

            Working...
            X