Announcement

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

  • Problem with Generating 10000 pairs of Gaussian AR(1) variables

    I am using program in Stata 15.1
    I need to generate 10000 pairs of Gaussian AR(1) variables
    yt = 0.15yt-1 + e1t, t = 2,..., 50,
    xt = 0.25xt-1 + e2t, t = 2,..., 50,
    with y1=e11 and x1=e21. et=(e1t e2t)' is mean zero. E(et et')=[1 0.27\0.27 1].
    I need to report the two sample means and the two sample variances of the 10000 pairs of sample means
    of the generated yt and xt.

    My codes are below:

    program ex, rclass
    clear
    matrix sigma=[1, 0.27\0.27, 1]
    matrix m=(0,0)
    drawnorm e1 e2, n(100) means(m) cov(sigma)
    qui gen t=_n
    qui gen y=.
    qui tsset t
    qui replace y=e1 if t==1
    qui replace y=0.15*l.y+e1 if t>1
    qui gen x=.
    qui replace x=e2 if t==1
    qui replace x=0.25*l.x+e2 if t>1
    sum y
    return scalar meany=r(mean)
    sum x
    return scalar meanx=r(mean)
    end
    clear

    When I run the program, the result is:
    no variables defined

    Could you please help me?
    Thank you very much!
    Best,
    Cherry
    Last edited by Cherry Yu; 01 Mar 2018, 17:35.

  • #2
    Dear Sir or Madam,
    I think I got the answer. You don't need to spend time on this question.
    Thank you very much!
    Best,
    Cherry

    Comment

    Working...
    X