Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Is there a command similar to "bys" if I want to gsort the variables?


From   gjhxmu@sina.com
To   statalist<statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: Is there a command similar to "bys" if I want to gsort the variables?
Date   Fri, 04 Dec 2009 11:32:24 +0800

Austin, Eric,and Kieran,Thank you very much for your replies.

I just want to make it easy when I want to arrange observations to be in descending order of the specified variables and  do something else following.

Just like "bys z1 z2: g num=_n" (this is just an example.)

Anyway,thank you for your help.

Kieran, why did the result of "d, short" in your typing show it was sorted by order, not year area?

d, short

Contains data
  obs:            17                          
 vars:             3                          
 size:           221 (99.9% of memory free)
Sorted by:  order
     Note:  dataset has changed since last saved

Thank you for any help.

Best regards

Rose




----- Original Message -----
From: Kieran McCaul <Kieran.McCaul@uwa.edu.au>
To: <statalist@hsphsun2.harvard.edu>
Subject: st: RE: Is there a command similar to "bys" if I want to gsort the variables?
Date: 2009-12-4 05:05:13

...

Is this what you want?


input year area
2000 1
2000 1
2000 2
2000 2
2001 1
2001 2
2001 3
2001 3
2001 3
2001 4
2002 2
2002 2
2002 4
2003 3
2003 3
2003 6
2003 6
end


gsort year -area, gen(order)
list
d, short

by order:gen num=_n
list

______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2701
Fax: (08) 9224 8009
email: Kieran.McCaul@uwa.edu.au

http://myprofile.cos.com/mccaul
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
If you live to be one hundred, you've got it made.
Very few people die past that age - George Burns

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of
gjhxmu@sina.com
Sent: Thursday, 3 December 2009 11:55 PM
To: statalist
Subject: st: Is there a command similar to "bys" if I want to gsort the
variables?

Dear statalists,

Is there a command similar to "bys" if I want to gsort the variables?

For example,

bys year (area): g num=_n


However, I want to gsort the variable of area.


I have tried as followings,

gsort year -area

by year: g num=_n


Is there an easier way to do it just like -bys-?


By the way, when I typed "d,short" after I typed "gsort year -area", the
result was as followings,

Contains data from study.dta
obs: 155 
vars: 6 5 Jun 2009 01:45
size: 3,875 (99.9% of memory free)
Sorted by: year

Why the sorted variable did not contain area?

Thank you for any help!

Best regards,

Rose


*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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