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: cutpoints for deciles


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: cutpoints for deciles
Date   Tue, 10 Jul 2012 15:03:17 +0200

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/


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