Announcement

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

  • Monte-Carlo simulation error:"no obeservations"

    Hello,

    I am new to Stata and for a project I have to peform a monte carlo simulation with 500 replications using three different sample sizes, being $N_1$ = 50, $N_2$ = 200 and $N_3$ = 2000

    Given: y1 = b0 + b1*y2 + b2*x1 + b2*x2
    and y2 = a0 + a1*x1 + a2*x1+a2*x2 + a3*z1 + a4*z2+a5*z3+a6*z6


    where y2 is the endogenious variable.

    Below is what I have programmed so far. The problem is that I keep getting the error "no observations". Though, I really do not see where the problem is as I have almost no experience in Stata. Can somebody please help me? Many thanks in advance!


    tempfile mc30 mc100 mc200 mc1600

    foreach n in 50 200 2000 {
    local j = 1
    while `j' <= 500 {
    quietly {
    preserve
    sample `n', count
    noisily di in yellow "." _continue


    gen x1= 2*uniform()
    gen x2 = rnormal(0,1)
    gen z1 = rnormal(4,10)
    gen z2 = (invnorm(uniform()))^2
    gen z3 = rnormal(2,3)
    gen z4 = rnormal(2,3)
    gen e = rnormal(0,1)
    gen v = rnormal(0,1)

    gen y2_50 = 1 + 1*x1 +1*x2+1*z1+1*z2+e
    gen y1_50 = 1 + y2_50 + x1 +x2 + v
    reg y2_50 x1 x2 z1 z2
    reg y1_50 x1 x2 y2_50
    matrix b1=e(b)
    svmat b1, name(ols) // save the regression coefficients and collapse in
    // order to only have one observation per coefficient

    collapse (mean) ols*

    gen N = `n'

    if `j' > 1 {
    append using `mc`n''
    }

    save `mc`n'', replace
    restore
    local j = `j' + 1
    }
    }
    di "`n'"
    }

    use `mc50', clear
    append using `mc100'
    append using `mc200'
    append using `mc2000'
    // here we append the four mc simulations (each with 1000 observations for B1
    // and B2) of four different sample sizes together to compare them in task 2.






  • #2
    Have you looked at
    Code:
    help simulate

    Comment


    • #3
      Dear, Mr. Jenkins,

      Yes I have looked at it, but it did not give me a solution to my question.

      Comment


      • #4
        I can't comment further with the information provided so far. I am confident that simulate would be a route to undertaking MC analysis, and don't understand why it is not part of your routine. Moreover, you have not provided sufficient information about your (simulated) data sets at each step in what you do -- so how can anyone tell where the problem might arise? Remember, as the Forum FAQ advises, (i) show us exactly what you typed and exactly what Stata gave back, and (ii) report all this using CODE delimiters (the use of which is easy and also explained in the FAQ. So one way to possibly get advice would be provide further information, e.g. including descriptive statistics and other output that is relevant to checking sample sizes

        Comment

        Working...
        X