Bookmark and Share

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   "C. Evans" <ce306@cam.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Sorting data in deciles and then regressing and storing coefficients. (Looping)
Date   10 Jul 2013 18:06:58 +0100

Dear Statalist

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index