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: generating dynamic panel data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: generating dynamic panel data
Date   Thu, 21 Jul 2011 08:37:29 -0500

The problem biting you is that for the first observation in each panel
_n - 1 evaluates to 0 and any reference to values in observation 0
results in missings. Such missings are then transmitted infectiously
to the entire panel.

Adding

... if _n > 1

will fix that.

Nick

On Thu, Jul 21, 2011 at 6:37 AM, billy mairs <[email protected]> wrote:
> Dear reader, I am having trouble trying to create dynamic panel data in stata.
>
> I want to generate panel data with say n=20, t=5. I want the panel data to be ar(1) and follow the form y(t) = 0.8*y(t-1) + 2*x(t) + u(t), i.e dynamic panel data. x(t) is a standard normally distributed random variable and u(t) is an error term that I can change the distribution of to assess non-normality robustness.It is important that the panels are independent.
>
> This is my attempt so far:
>
> clear all
> set obs 20
> gen i = _n
> gen y = rnormal()
> expand 5
> sort i
> by i: gen t=_n
> gen x = rnormal()
> gen u = rchi2(2)
>
> and then using something like
>
> by i: replace y = 0.8*y[_n-1] + 2*x + u
>
> in the hope that I have 20 independent cross sections that follow an ar(1) process. However the above method will generate missing values. Any help will be greatly appreciated.

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