Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Creating ten 10%-portfolios


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Creating ten 10%-portfolios
Date   Fri, 1 Mar 2013 17:39:54 +0000

It sounds as if you need to check out the -xtile()- function in
-egenmore- (SSC).

Alternatively, here is a solution from first principles for what I
think you are asking, but I have just written this down, not tested
it.

gen mdate = ym(year month)
egen group = group(mdate)
su group, meanonly
local max = r(max)

gen portfolio = .

qui forval i  = 1/`max' {
        xtile temp=illiq if group == `i'
        replace portfolio = temp if group == `i'
        drop temp
}


Nick

On Fri, Mar 1, 2013 at 4:00 PM, Bo Spiljard <bo.spiljard@gmail.com> wrote:

 I am testing a version of the
> CAPM and I need to make ten 10-percentile portfolios (sub groups) and
> these have to be revised each month. This has to be done by creating a
> new variable that contains the numbers 1 to 10 and each number should
> represent a portfolio.
>
> Normally if I am stuck I could find the answer by searching on
> statalist, but this problem I could not find. I allready tried alot of
> things myself (i.e. using r(p10)) etc, but I cannot find the right
> code. The data I have is: id, date (year, month and day), and illiq. I
> need to create 10 equal portfolios based on the proportion of illiq
> and this have to be revised each month. So each of the portfolio at
> each month has to contain the same amount of ids, with in portfolio 1
> the id with the lowest value of illiq, in portfolio 2 the id with
> slightly higher illiq, etc..
>
> Also the data for each firm does not start and not end at the same
> date and also for each date there is missing information, so I cannot
> purely use the sort function.
>
> Here is an simplified example with allready portfolios added how it
> should look like.
>
> id            year       month  day        illiq         portfolio
>
> 1             2001      1             1             15           3
>
> 2             2001      1             1             13           2
>
> 3             2001      1             1             12           1
>
> 1             2001      1             2             11           3
>
> 2             2001      1             2             8             2
>
> 3             2001      1             2             13           1
>
> ...
>
> 1             2001      2             1             10           3
>
> 2             2001      2             1             9             2
>
> 3             2001      2             1             7             1
>
> ...
>
> 1             2009      12           31           8             1
>
> 2             2009      12           31           11           2
>
> 3             2009      12           31           13           3
>
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index