Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: constructing subsamples at every year


From   Lee Sieswerda <Lee.Sieswerda@tbdhu.com>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: constructing subsamples at every year
Date   Wed, 16 Jul 2003 17:43:55 -0400

-by- is a short cut that you can replace with a -for[each/values]- loop.
This is an example with the auto data:

sysuse auto
forvalues n=1/5 {
	xtile temp`n'=price if rep78==`n', nq(4) 
}
egen myvar = rsum(temp1-temp5)

It loops over the values of rep78 (or any grouping variable) creating
quantiles for each level of rep78 in a new variable. That gives you five (in
this case) separate variables: one for each level of rep78. Depending on
what you want to do next, you can then combine them all into a single
variable using -egen, rsum-.

Best,
Lee Sieswerda

Lee Sieswerda, Epidemiologist
Thunder Bay District Health Unit
Lee.Sieswerda@tbdhu.com





-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] 
Sent: Wednesday, July 16, 2003 3:38 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: constructing subsamples at every year


Dear Statalist users:

I would like to construct subsamples at every year based on a ranking of a
variable. xtile allows us to do it for the entire sample but it cannot be
used with the by command.  Is it possible to get around this?

Thank you,

Ayla

Note: Hypothetically what I would like to do is

by year: xtile newvar=oldvar nq(4)


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index