Statalist


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

st: Re: change the place of observations in editor


From   Jorge Eduardo Perez Perez <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Re: change the place of observations in editor
Date   Sat, 16 Jan 2010 13:04:54 -0500

Use the "stack" command as follows:

. list

     +-------------------------------------+
     | group1   result1   group2   result2 |
     |-------------------------------------|
  1. |      1         1        0         0 |
  2. |      1         0        0         1 |
  3. |      1         1        0         0 |
  4. |      1         0        0         1 |
  5. |      1         1        0         0 |
     +-------------------------------------+

. stack group1 result1  group2 result2, into(group result) clear

. list

     +-------------------------+
     | _stack   group   result |
     |-------------------------|
  1. |      1       1        1 |
  2. |      1       1        0 |
  3. |      1       1        1 |
  4. |      1       1        0 |
  5. |      1       1        1 |
     |-------------------------|
  6. |      2       0        0 |
  7. |      2       0        1 |
  8. |      2       0        0 |
  9. |      2       0        1 |
 10. |      2       0        0 |
     +-------------------------+

_______________________
Jorge Eduardo Pérez Pérez

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