Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: generating variables with panel data


From   n j cox <[email protected]>
To   n j cox <[email protected]>
Subject   Re: st: Re: generating variables with panel data
Date   Fri, 18 May 2007 18:32:40 +0100

Dopey misprints corrected.

n j cox wrote:

This solution may well work for your set-up, but
it is not the most general solution. Next time
you have an unbalanced panel, no such trick
is guaranteed to work. A secondary disadvantage
is that unless you add a comment to your
do or log files, the rationale for this approach
will be increasingly difficult to remember.

Another approach is as follows:

gen real = exch if year == 2000
bysort id (real) : replace real = real[1]
			     ^^^^   ^^^^	
The logic of this is very Stataish.

In the first statement, we ensure that
only values for 2000 are used. For
years other than 2000, -real- is thus set
to missing.

Thus after

bysort id (real):

the data will look somewhat like this:

id        year   real
Australia 2000  whatever
Australia 1992     .
Australia 1994     .
Australia 2002     .
...
Austria    2000 something else
Austria    1999    .
Austria    1989    .
....

so that

        replace real = real[1]

will then copy values downward within
each panel. Also, if any panel
does not include values for 2000, then all
values of -real- will end up missing for
that panel.

There is some database jargon for this process
of "spreading" a value to an appropriate subset
of the data. Perhaps it is "spreading", but I've
forgotten what it is. Anyway, a database expert on this
list may be able to remind me.

Nick
[email protected]

Nico

I figured it [...]

I sorted by id and then subscripted my exchange rate
for the 11th obvservation, which is the year 2000 in
my case:

by id: gen real=exch[11]

As far as I can tell, it worked.

--- Nico

 > I have a panel of 50 countries, 14 years, with the
 > dollar exchange rate being one of the variables.
 > For
 > example:
 >
 > Australia 1990 austexch1990
 > Australia 1991 austexch1991
 > Australia 1992 austexch1992
 > Peru      1990 peruexch1990
 > Peru      1991 peruexch1991
 > Peru      1992 peruexch1992
 > etc.
 >
 > The problem I am having is that I want to generate a
 > variable equal to the exchange rate in 2000 for each
 > country:
 >
 > Australia 1990 austexch2000
 > Australia 1991 austexch2000
 > Australia 1992 austexch2000
 > Peru      1990 peruexch2000
 > Peru      1991 peruexch2000
 > Peru      1992 peruexch2000
 > etc.
 >
 > It must be very easy to do, but I don't know how to
 > specify it.  I don't believe any of the expressions
 > listed in help for 'egen' serve me either.  Any
 > suggestions would be appreciated.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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