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: Fwd: xtile: how to make it fast


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Fwd: xtile: how to make it fast
Date   Fri, 8 Feb 2013 20:44:15 +0000

You won't get anywhere near 40k distinct values for your new variable
unless -X- really has many, many distinct values.

cumul X [fw=W], gen(pc) equal

will generate cumulative fractions. You can coarsen it further if you
wish, but my guess it will have far fewer than 40,000 distinct values.
That should be faster than what you are trying.

The key here is that the weights don't affect the principle that equal
values should be assigned the same quantile. (If you want to break
that principle, you would need to write your own command.)

Nick

On Fri, Feb 8, 2013 at 4:39 PM, Luigi Pinoni <gipino9@gmail.com> wrote:

> Do you know any a faster way of doing what ^xtile^ command does?
>
> Let me explain my problem:
>
> I have a variable, say X, with 50k observations, and a frequency
> weights, say W, which is on average 6k. I need to generate a new
> variable that categorizes X by a large number of quantiles (40k).
>
> I need something that ideally ^xtile^ command does but it takes ages.
> My command line for variable X is:
>
> xtile double pc = X [fw = W]. nq(40000)
>
> I guess the problem is that xtile is written as an ado file without
> using Mata and it loops forever and ever.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index