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 15:33:54 +0200

Many thanks!

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

> On Tue, Jul 10, 2012 at 2:48 PM, "Fabian Schönenberger" wrote:
> > 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?
> 
> *------------ begin example --------------
> // create some panel data
> clear
> set obs 37
> gen year = 1975+_n
> expand 10
> gen x = rnormal()
> 
> // create the bins by year
> sort year
> by year : egen min = min(x)
> by year : egen max = max(x)
> 
> gen x_std = ( x - min) / ( max - min )
> gen x_10cat = ceil(10 * x_std)
> gen x_5cat  = ceil( 5 * x_std)
> 
> // deal with the minimun
> replace x_10cat = 1 if x_10cat == 0
> replace x_5cat  = 1 if x_5cat  == 0
> 
> // display
> list in 1/25, sepby(year)
> *----------- end example -----------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
> 
> 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