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 <>
To   "''" <>
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-.

Lee Sieswerda

Lee Sieswerda, Epidemiologist
Thunder Bay District Health Unit

-----Original Message-----
Sent: Wednesday, July 16, 2003 3:38 PM
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,


Note: Hypothetically what I would like to do is

by year: xtile newvar=oldvar nq(4)

*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index