Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Sorting data in deciles and then regressing and storing coefficients. (Looping)
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Sorting data in deciles and then regressing and storing coefficients. (Looping)
Date
Wed, 10 Jul 2013 18:14:00 +0100
1. The version of -xtile()- on SSC is
*! _gxtile version 1.2 UK 08 Mai 2006
Your version statement must refer to something else.
2. -rowtotal()- is part of -egen-, i.e. part of official Stata.
3. The command
egen portfolio = rowtotal()
isn't legal. Please say what you did use to get better advice.
Nick
[email protected]
On 10 July 2013 18:06, C. Evans <[email protected]> wrote:
>
> Jeph, thanks for the suggestion it solved my problem (suggestion can be seen
> below). My version of -xtile()- which can be found in -egenmore- SSC. Is :
> version 3.1.6 04feb2013 . I'm using Stata 12.1. My aim was to create 10
> 'portfolios' a year based on -size- . Jeph's code and then -rowtotal()-
> solves this.
>
> The output that the command produced is below. I then used:
>
> egen portfolio = rowtotal()
>
> which is also from -egenmore- (SSC).
> -sample()- as I suggested earlier was not needed. -sample()- was just to
> reduce the number of observations by drawing a random sample from my dataset
> and using that instead of the full dataset.
>
>
> id year size por~1964 por~1965 por~1966 por~1967.... |
>
> |----------------------------------------------------------------------|
> 1. | 10006 1964 219303.1 8 . . . |
> 2. | 10006 1965 249306.1 . 8 . . |
> 3. | 10006 1966 272942.9 . . 8 . |
> 4. | 10006 1967 277828.9 . . . 7 |
> 5. | 10006 1968 291790.6 . . . . |
>
> |----------------------------------------------------------------------|
> 6. | 10006 1969 289380.5 . . . . |
> 7. | 10006 1970 244459.8 . . . . |
> 8. | 10006 1971 297727.2 . . . . |
> 9. | 10006 1972 267790.8 . . . . |
> 10. | 10006 1973 256238.1 . . . . |
>
> |----------------------------------------------------------------------|
> 11. | 10006 1974 240341.8 . . . . |
> 12. | 10006 1975 230729.7 . . . . |
> 13. | 10006 1976 285526.4 . . . . |
> 14. | 10006 1977 304096.8 . . . . |
> 15. | 10006 1978 291149.2 . . . . |
>
> Thanks for all of the help,
> Chris
>
>
> On Jul 10 2013, Jeph Herrin wrote:
>
>>
>> Try this:
>>
>> * -- make portfolios -- *
>> levelsof year, local(years)
>> foreach Y in `years' {
>> xtile portfolio_`Y'=cond(year==`Y',size,.), nq(10)
>> }
>>
*
* 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/