Statalist The Stata Listserver


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

st: RE: rearrange variables in a panel


From   "Maarten Buis" <[email protected]>
To   <[email protected]>
Subject   st: RE: rearrange variables in a panel
Date   Mon, 6 Nov 2006 10:57:05 +0100

---Alessandro Fiaschi wrote:
> Even if I add an "id (=1,2,3,...)" for each firm, "gsort id -time"
> makes only an order, but it doesn't rearrange data in the inverse
> order (from 2005 to 1993, in my case). Could you help me more? Thanks!

Alex:
I interpreted your question as: "I want to keep observations
belonging to the same firm together, but want to change the
sort order within each firm from most recent to least recent."
In that case you would type -gsort id -year-. I could have
also read your question as: "I want all the most recent
observation first and the least recent last." Then you would
type: --gsort -year id-. This is illustrated in the example
below.
HTH,
Maarten

*--------------begin example----------------
use http://www.stata-press.com/data/r9/pig, clear
list id week in 1/20, clean
gsort id -week
list id week in 1/20, clean
gsort -week id
list id week in 1/20, clean
*--------------end example------------------

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------



*
*   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