Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: Simulating an AR(1) in Stata

 From Syed Basher To statalist@hsphsun2.harvard.edu Subject st: Simulating an AR(1) in Stata Date Wed, 23 Feb 2011 22:36:01 -0800 (PST)

```Dear Statalist users,

I am using Stata 11.1.  I am trying to generate 500 sequences of first-order
autoregressive processes with AR(1) parameters randomly drawn from the
[0.48,0.83] interval, and disturbances drawn from a zero-mean normal
distribution where the standard deviation was randomly selected from the
[0.005,0.014] interval. With the help of earlier Stata posts, I have come up
with the following:

****************************************
clear
version 11.1
quietly set obs 500
set seed 10101
gen t=_n
scalar a = 0.48
scalar b = 0.83
scalar c = 0.005
scalar d = 0.014
gen rho = a+(b-a)*runiform()
gen s = c+(d-c)*runiform()
gen et = rnormal(0, s)
gen yt=.
replace yt=et in 1
forvalues i=2(1)500 {
quietly replace yt=rho*yt[`i'-1]+et[`i'] in `i'
}
line yt t
****************************************

I would appreciate if someone kindly proofread the above program for any
mistake(s).  Eventually I will use the AR(1) processes to simulate 5% critical
values of a statistic for which I will later seek Statalist's help. Thank you.

Syed Basher
Qatar Central Bank
and
Qatar National Food Security Program

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```