Statalist


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

Re: st: change the place of observations in editor


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: change the place of observations in editor
Date   Sat, 16 Jan 2010 11:46:28 -0600

Take a look at -reshape- and the FAQ on -reshape- (-findit reshape- to locate).

For example:

clear*
input group1  result1 group2  result2
1       1       0       0
1       0       0       1
1       1       0       0
1       0       0       1
1       1       0       0
end

gen id = _n
reshape long group result, i(id)
gsort -gr id
l

Scott


2010/1/16 Ichiro M. Omori <[email protected]>:
> Dear Statalist,
>
> I am using Stata/SE 11 for Windows  to try to change the place of
> observations in editor.
>
> From
>
> group1  result1 group2  result2
> 1       1       0       0
> 1       0       0       1
> 1       1       0       0
> 1       0       0       1
> 1       1       0       0
>
>
> To
>
> group   result
> 1       1
> 1       0
> 1       1
> 1       0
> 1       1
> 0       0
> 0       1
> 0       0
> 0       1
> 0       0
>
> I wrote a do file to conduct this change as below.
> -----------------------------------------------
>
> clear
> foreach var in ///
>        group1 result1 group2 result2 {
> gen `var'=.
> }
>
> set obs 5
> replace group1=1
> replace group2=0
>
> replace result1=1 in 1
> replace result1=0 in 2
> replace result1=1 in 3
> replace result1=0 in 4
> replace result1=1 in 5
>
> replace result2=0 in 1
> replace result2=1 in 2
> replace result2=0 in 3
> replace result2=1 in 4
> replace result2=0 in 5
>
> preserve
>        drop group2 result2
>        rename group1 group
>        rename result1 result
>        save groupresult.dta,replace
> restore
>
> drop group1 result1
>        rename group2 group
>        rename result2 result
> append using groupresult.dta
>
> --------------------------------------------------
> But I would like to know how can I do it more simple way, without making
> dta.file.
>
> Can someone help me with this?
>
>
> Regards,
>
> Ichiro
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index