Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: xtile and "by" question

From   Edgard Alfonso Polanco Aguilar <>
Subject   Re: st: xtile and "by" question
Date   Tue, 08 May 2007 18:42:30 -0500

Hi everybody,

Sergio, your hack was very helpful, it works great but in some dates it skips a quantile in some specific cities. For example, in the last period it "jumps" from quantile 4 to quantile 6. Don't you know why something like this would happen? I'm not very accustomed to macros and some of the syntax you used.


Sergio Correia escribió:

Well, it seems that you should hack around that problem.
Something like this may help

* 1) Let's create a variable with the levels, and save them on a local macro
egen levels = group(date city)
levelsof levels, local(levels)

* 2) Now let's run a loop
gen output = .
foreach l of local levels {
xtile temp=income if levels==`l'
replace output = temp if output==.
drop temp

I tried it on some dummy data and it appeared to work.


On 5/8/07, Edgard Alfonso Polanco Aguilar <> wrote:

Hello everybody,

I'm working with a database which consists on income by month and
region. I need to classify the income by percentiles by city and month
because there's a wide dispersion on income levels across cities, to the
point that the highest income in one is on the median of another. I know
the command of choice for this task is xtile, but Stata doesn't allow me
to use it with "by" like in "by city date: xtile var=income nq(10)". I'm
working in Stata 9 SE for Windows.



*   For searches and help try:

fn:Edgard Alfonso Polanco Aguilar
n:Polanco Aguilar;Edgard Alfonso
tel;work:339 4949 ext: 2104
tel;cell:316 577 9895

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