Statalist


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

st: RE: xtile from the start of a period


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: xtile from the start of a period
Date   Tue, 26 Feb 2008 07:05:27 -0000

Hi,

Maybe something like this ???

First I create a variable monthnum ( equal to 1, 2,etc) to identify the
month jan.
I also create a variable year 

Then 

*******start*******

gen file=1 if monthnum==1
gen decile=.

* assuming start of the dataset is 1982 and end is 2005 and portfolios are
formed every five years.

forvalues year = 1970(5)2005 {
xtile decile`year'=mcap if year==`year' & file==1, n(10) replace
decile=decile`year' if decile==.
drop decile`year'
}

sort compid

* foreach company replace the missing decile with the last value of decile

by compid: replace decile = decile[_n-1] if decile >=.

******end********

For more on last observation carried forward see
http://www.stata.com/support/faqs/data/missing.html

Also, there is a user written ado carryforward

. ssc install carryforward

Cheers
rajesh

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of John Hund
Sent: 25 February 2008 23:27
To: [email protected]
Subject: st: xtile from the start of a period

Hey all--

A simple question whose answer I can't find in the very interesting  
xtile by groups discussion.  In this case I have data (market values)  
on companies (compid) monthly. Ideally I would like to generate a  
variable containing the decile rank of the company based on their  
market value at the beginning of a period (i.e. their decile in  
January 1970) and have that variable contain the decile rank for all  
monthly observations of the compid for a particular time window (i.e.  
1970-1975). That is, there would be a variable that contains the  
decile rank from Jan70 for all monthly observations of a compid for  
the next 5 years.  I suspect that my question is less about xtile and  
more about filling in, since it is easy to get the decile rank for  
the first month...I just can't "fill" it in for the next (in this  
case) 59 observations of each company.

Thanks for your help,
John

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