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

Re: st: How function "group" works in Stata?


From   [email protected]
To   [email protected]
Subject   Re: st: How function "group" works in Stata?
Date   Fri, 02 Jul 2004 12:27:54 -0500

Shourun Guo <[email protected]> asks:

> Say I have a variable "a" and 10 observations with the value
> 1,2,3,...,10.
> 
> gen b=group(2), I will get 2 evenly divided subsample. variable
> "b" has the value 1,1,1,1,1,2,2,2,2,2.
> 
> but if I input, gen c=group(a), variable "c" will have the value
> 1,1,1,2,3,4,5,7,8,10.
> 
> How the value of "c" is assigned? Just curious.

Try the following and see if this helps you understand why.

    clear
    set obs 10
    gen byte a = _n
    forvalues i = 1/10 {
        gen byte b`i' = group(a[`i'])
    }

    gen c = group(a)

    list

Now notice that

        c[1] = b1[1]
        c[2] = b2[2]
        c[3] = b3[3]
        c[4] = b4[4]
        c[5] = b5[5]
        ...

I hope that this small demo clarifies.  If not let me know and
I will try to explain it in some other way.

Ken Higbee    [email protected]
StataCorp     1-800-STATAPC

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index