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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: cutpoints for deciles


From   "Fabian Schönenberger" <sch.f@gmx.ch>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: cutpoints for deciles
Date   Tue, 10 Jul 2012 14:48:59 +0200

Many thanks!

Is it possible to loop over years?

forvalues t = 1976/2012 {
> sum x if year=`t', meanonly
> gen x_cat = (x - r(min)) / (r(max)-r(min)) x if year=`t'
> replace x_cat = ceil( 10 * x_cat) x if year=`t'
}

How do I have to adjust the formula to generate 5 bins?

Thanks, Fabian


-------- Original-Nachricht --------
> Datum: Tue, 10 Jul 2012 14:14:55 +0200
> Von: Maarten Buis <maartenlbuis@gmail.com>
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: cutpoints for deciles

> On Tue, Jul 10, 2012 at 1:44 PM, "Fabian Schönenberger" wrote:
> > My goal is to assign each company to a decile according to its market
> capitalization on a yearly basis. Instead of forming equally distributed
> portfolios with xtile2 (Stata module by Wang), I want the assignment based on
> 10 cutpoints of the market capitalization.
> >
> > For example: If in year 1 the smallest company is 200, the largest 2000,
> there are the following cutpoints:
> 200,380,560,740,920,1100,1280,1460,1640,1820,2000. A company with market capitalization of 250 should be in
> portfolio 1, one with 1900 market capitalization in portfolio 10.
> 
> First of all, I would not call these deciles, you might call them bins.
> 
> Here is one solution:
> 
> *-------------- begin example --------------
> clear
> input x
> 200
> 250
> 1900
> 2000
> end
> 
> sum x, meanonly
> gen x_cat = (x - r(min)) / (r(max)-r(min))
> replace x_cat = ceil( 10 * x_cat)
> list
> *--------------- end example ---------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
> 
> Also see: Nicholas J. Cox (2003) Stata tip 2: Building with floors and
> ceilings. The Stata Journal, 3(4): 446-447.
> <http://www.stata-journal.com/article.html?article=dm0002>
> 
> Hope this helps,
> Maarten
> 
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
> 
> 
> http://www.maartenbuis.nl
> --------------------------
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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