Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Simulating an AR(1) in Stata


From   Syed Basher <[email protected]>
To   [email protected]
Subject   Re: st: Simulating an AR(1) in Stata
Date   Thu, 24 Feb 2011 02:33:16 -0800 (PST)

Thank you Nick. Here is a rephrasing of my intent:

I want to generate 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. I am using the following steps for my 
purpose. Does this look okay? Thank you. 

**************************************
clear
version 11.1
quietly set obs 100
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)
quietly gen yt= et in 1
quietly replace yt=rho*yt[_n-1]+et in 2/L
exit
**************************************




----- Original Message ----
From: Nick Cox <[email protected]>
To: [email protected]
Sent: Thu, February 24, 2011 1:13:38 PM
Subject: Re: st: Simulating an AR(1) in Stata

This program does not produce 500 series. It creates a single series
with 500 observations in which  rho varies from observation from
observation,  and the SD of the normal distribution varies ditto. So,
I guess it does not match your intent.

Also note that the loop over observations is unnecessary:

quietly gen yt= et in 1
quietly replace yt=rho*yt[_n-1]+et in 2/L

would I  imagine match your intent.

Nick

On Thu, Feb 24, 2011 at 6:36 AM, Syed Basher <[email protected]> wrote:

> 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/



      
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index