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

# Re: st: replacing values in panel data

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: replacing values in panel data Date Wed, 27 Jul 2011 14:10:29 +0100

```bysort t (i) : replace u = u[1] if _n > 1

Nicholas J. Cox. 2011. Speaking Stata: Compared with ...
The Stata Journal 11(2): 305-314.

Abstract.  Many problems in data management center on relating values
to values in other observations, either within a dataset as a whole or
within groups such as panels. This column reviews some basic Stata
summarize, by:, sum(), cond(), and egen. Several techniques exploit
the fact that logical expressions yield 1 when true and 0 when false.
Dividing by zero to yield missings is revealed as a surprisingly
valuable device.

On Wed, Jul 27, 2011 at 1:53 PM, billy mairs <mairs8@hotmail.com> wrote:

> I have a panel data set and wish to replace multiple values over the different cross sections.
>
> Say the panel data is N=20 and T=5. I have 5 values for a standard normal error term ‘u’ (for every t) for my first panel, say i = 1. I want to copy these 5 values into the other cross section units, so that u is the same in the other 19 panels as it is in my first panel. Here is what I have come up with so far
>
> clear all
> set obs 20
> gen i = _n
> expand 5
> sort i
> by i: gen t=_n
> tsset i t
> gen x = rnormal()
> gen u = rnormal() in 1/5
> br
>
> How would I then copy the values for u into the missing values so that at each t, u is the same across the panels?
> I hope to then use the command
>
> replace u = (0.5)*u + ((1-0.25)^0.5)*rnormal() if i>1
>
> in order to create dependence in error terms across the panels. Thanks for your time

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