Statalist The Stata Listserver


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

st: Re: Create dummy variable in panel


From   "Zou Hong" <[email protected]>
To   <[email protected]>
Subject   st: Re: Create dummy variable in panel
Date   Sat, 3 Feb 2007 10:36:44 +0800

Christian,

Try the following:

sort year
by year: egen median_by_year=median(ta)
gen large==0
replace large=1 if ta>median_by_year

Joe

----- Original Message ----- From: "Christian Andres" <[email protected]>
To: <[email protected]>
Sent: Saturday, February 03, 2007 10:05 AM
Subject: st: Create dummy variable in panel



Hi,

I have a problem generating a dummy variable in a panel dataset.

My dataset contains 300 companies over 10 years. For each company, I have a size measure, total assets (ta). What I want to do now, is to generate a dummy variable which is 1 if the company's size is larger than the sample median in each year. This means that I need ONE variable, say "large" which first lists this measure for ten years for company 1, then 10 years for company 2...

To make things easier to understand:
In year 1996 the median is 50, in 1997 60, in 1998 55:

company year ta DUMMY_LARGE
1 1996 51 1
1 1997 53 0
1 1998 56 1
1....

I tried some gen and egen commands using by:year, but I did not come up with a solution.

Thank you very much for any suggestion!
Christian
*
* 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/

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