Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Convert STATA format


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: Convert STATA format
Date   Mon, 17 Feb 2014 10:53:29 +0100

This looks simple (MS excel's shift cells up.) BUT it has serious
consequences that one should be aware of.

Responding to a similar query in 2010, Maarten Buis warned

"You cannot delete a cell and at the same time keep the other
variables intact...It is absolutely crucial that the values that to
the same observations (i.e. a row in your) always stay together. You
can move entire up or down, or you can move columns left or right, you
must never move individual cells up or down  left or right. If that
happens your entire dataset instantly become completely worthless."
http://www.stata.com/statalist/archive/2010-08/msg00720.html

If, having read this, you still want to proceed, one way to go is to
follow Scott Merryman's solution
(http://www.stata.com/statalist/archive/2010-08/msg00716.html).
Something along the lines

clear *
input Var1   Var2   Var3
       1      .      .
       1      .      .
       .      2      .
       .      2      .
       .      .      3
       .      .      3
end

foreach v of varlist Var1 Var2 Var3 {
                putmata `v'
                mata: `v'=sort(`v',1)
                getmata `v', replace
}

drop if Var1 == .  /*If your data are significantly different than
example you shared, you will need to adapt this */


Ronnie

On Mon, Feb 17, 2014 at 10:14 AM, Qian Yu <[email protected]> wrote:
> Dear all
>       How to compile the results in stata file?
>       The results is as following
>       Var1   Var2   Var3  ...   Var"n"
>         1
>         1
>                  2
>                  2
>                           3
>                           3
>                                 .
>                                 .
>                                 .
>                                           n
>                                           n
>      I want to obtain the following format in stata
>     Var1   Var2   Var3   ...   Var"n"
>         1      2       3     ...       n
>         1      2       3     ...       n
>
> So could anyone give me some advice on the STATA code for this conversion?
>
>
> Many thanks in advance!
> Qian
>
>
>
> --
> View this message in context: http://statalist.1588530.n2.nabble.com/Convert-STATA-format-tp7580483.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   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/
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index