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   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Sorting data in deciles and then regressing and storing coefficients. (Looping)
Date   Thu, 11 Jul 2013 09:11:12 -0400

If you want one portfolio variable (rather than different ones for different years) you may want to simplify:

gen portfolio=.
levelsof year, local(years)
foreach Y in `years' {
         xtile tmp=cond(year==`Y',size,.), nq(10)
         replace portfolio=tmp if year==`Y'
	 drop tmp
}


J

On 7/11/2013 6:16 AM, C. Evans wrote:
Please see below for my problem which has now been solved.
1. I am using -xtile-. Typing -which xtile- in Stata shows me:
*! version 3.1.6  04feb2013
Yet typing -which _gxtile- gives me:
*! _gxtile version 1.2 UK 08 Mai 2006

What would be the difference here as I don't know.

3. The exact command I typed to set up my portfolios. Firstly using J's suggested command, then using -rowtotal-

-levelsof year, local(years)-
-foreach Y in `years' {
        xtile portfolio_`Y'=cond(year==`Y',size,.), nq(10)
}-
-egen portfolio = rowtotal( portfolio_1964 portfolio_1965 portfolio_1966 portfolio_1967 portfolio_1968 portfolio_1969
portfolio_1970 portfolio_1971 portfolio_1972 portfolio_1973 portfolio_1974 portfolio_1975 portfolio_1976 portfolio_1977
portfolio_1978 portfolio_1979 portfolio_1980 portfolio_1981 portfolio_1982 portfolio_1983 portfolio_1984 portfolio_1985
portfolio_1986 portfolio_1987 portfolio_1988 portfolio_1989 portfolio_1990 portfolio_1991 portfolio_1992 portfolio_1993
portfolio_1994 portfolio_1995 portfolio_1996 portfolio_1997 )-
-drop portfolio_1964 portfolio_1965 portfolio_1966 portfolio_1967 portfolio_1968 portfolio_1969 portfolio_1970
portfolio_1971 portfolio_1972 portfolio_1973 portfolio_1974 portfolio_1975 portfolio_1976 portfolio_1977 portfolio_1978
portfolio_1979 portfolio_1980 portfolio_1981 portfolio_1982 portfolio_1983 portfolio_1984 portfolio_1985 portfolio_1986
portfolio_1987 portfolio_1988 portfolio_1989 portfolio_1990 portfolio_1991 portfolio_1992 portfolio_1993 portfolio_1994
portfolio_1995 portfolio_1996 portfolio_1997-

This was because the command created portfolios for all of the years in my dataset which was 1964 to 1997. I just wanted
one variable to display all of the portfolio numbering and as such used -rowtotal- and then dropped the other portfolio
variables.

Thanks again for all the help with this problem,
Chris

On Jul 10 2013, Nick Cox wrote:

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


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