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

Re: st: rearranging observations within a variable


From   Edwin Leuven <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: rearranging observations within a variable
Date   Tue, 10 Feb 2004 17:55:39 +0100 (CET)

g e = var - var[_n-1]
expand e
sort var
replace var = . if var!=_n
drop e


On Tue, 10 Feb 2004, Daniel Mueller wrote:

> Hi.
> 
> There's probably a neat trick to that, but can't find it...
> 
> I have one variable:
>      +-----+
>      | var |
>      |-----|
>   1. |   1 |
>   2. |   3 |
>   3. |   5 |
>   4. |   7 |
>   5. |   9 |
>      |-----|
>   6. |  11 |
>   7. |  13 |
>   8. |  15 |
>   9. |  17 |
>  10. |  19 |
>      +-----+
> 
> The observations of this variable I want to rearrange to arrive at the following:
>      +-----+
>      | var |
>      |-----|
>   1. |   1 |
>   2. |   . |
>   3. |   3 |
>   4. |   . |
>   5. |   5 |
>      |-----|
>   6. |   . |
>   7. |   7 |
>   8. |   . |
>   9. |   9 |
>  10. |   . |
>      +-----+
> i.e. I have to -expand- the data set to get running observation numbers with missing values for observations, which were
> previouly missing.
> 
> How can I do that??
> 
> Thanks a bunch in advance,
> greetings,
> Daniel
> 
> 
> 
> *
> *   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/
> 

-- 
Edwin Leuven
Department of Economics
University of Amsterdam
Roetersstraat 11
1018 WB Amsterdam
the Netherlands
tel: +31 20 525 5241
fax: +31 20 525 4310
http://www.fee.uva.nl/scholar/mdw/leuven
*
*   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