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

Re: st: Generating a bounded AR(1) series for Monte-Carlo Simulation

From   Austin Nichols <>
Subject   Re: st: Generating a bounded AR(1) series for Monte-Carlo Simulation
Date   Sat, 11 Jul 2009 09:32:33 -0400

Paddy Carter<> :

Read -help ifcmd- and note that

if year>1 {
 some code

executes "some code" only if the first observation on year in the data
is greater than 1.  Similar problems apply to the if commands you have
put inside the main set of braces.

On Sat, Jul 11, 2009 at 9:02 AM, Paddy Carter<> wrote:
> Dear Statalisters
> I have a puzzle, concerning a section of a program intended to generate an
> AR(1) series for `aid' that is bounded between 0 and 0.3
> Prior to this section of the program, I have already generated countries,
> time (and xtset the data) and a variable `aid' consisting of random draws
> from a uniform distribution on [0,0.3]  - all but the first observation of
> which for each country, I wish to replace, using the following code:
> if year>1 {
>        if  L.aid<0  {
>           replace aid=const+`rho'*L.aid+rnormal(0.1,0.01)
>                   }
>        else if L.aid>0.3 {
>           replace aid=const+`rho'*L.aid+rnormal(-0.1,0.01)
>                   }
>        else {
>            replace aid=const+`rho'*L.aid+(rnormal()/100)
>                   }
>           }
> I expect this code to do the following: whenever aid wanders beyond the
> bounds 0 and 0.3, the shock in the next period is set to bounce it away from
> these bounds. Hence I would expect to see observations of aid that do stray
> beyond 0 and 0.3 but which bounce back in the subsequent period. My puzzle
> is that when I run this code with large T, the aid series never strays
> beyond bounds. By my understanding, that shouldn't be happening.
> I would actually like to write a program such that aid never strays beyond
> bounds, but I didn't know how to; I appear to have done so inadvertently,
> but the fact I don't understand what it's doing makes me fear I've gone
> totally wrong.
> I apologise if I'm missing something obvious; this is my first ever attempt
> at programming.
> This is on Stata/IC 10.1 for Windows

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index