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]

From |
Scott Merryman <scott.merryman@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Data Management Loop |

Date |
Fri, 1 Apr 2011 15:24:10 -0500 |

Here is one way to restructure your data: clear input id type x 1 1 1 2 2 2 3 1 3 4 2 4 5 1 5 6 2 6 end preserve reshape wide x, j(id) i(ty) tempfile tmp sort type replace type = 2*(type==1) + (type==2) save `tmp' restore merge m:1 type using `tmp' drop _m sort id type l Scott On Fri, Apr 1, 2011 at 1:45 PM, Toby <spiegeldesaster@googlemail.com> wrote: > Thanks for your reply! > > Doing this, I think (!) I can compare the the x value of type 1 with > every other x value of type 2. This will give me a hint about how > often a certain value x of type 1 is higher/lower/ or equal compared > to all other values in the sample. Vice versa for type 2. Due to my > limited programming capabilities I thought this would be an easy way. > Do you think there is a better way? (Certaintly there is. =) ) > > Toby. > > > 2011/4/1 Nick Cox <njcoxstata@gmail.com>: >> I think the main question is not how to get this, but how and why do >> you imagine it will help you? >> For each type, the information is already accessible. Why repeat it? >> >> Nick >> >> On Fri, Apr 1, 2011 at 7:14 PM, Toby <spiegeldesaster@googlemail.com> wrote: >>> Hello Statalist, >>> >>> i have a problem with the following data structure: >>> >>> id type x >>> 1 1 1 >>> 2 2 2 >>> 3 1 3 >>> 4 2 4 >>> 5 1 5 >>> 6 2 6 >>> >>> Now I want to generate additional variables that include the x value >>> for the opposite type, so that the data looks like this: >>> >>> id type x x_2 x_4 x_6 x_1 x_3 x_5 >>> 1 1 1 2 4 6 >>> 2 2 2 . . . 1 3 5 >>> 3 1 3 2 4 6 >>> 4 2 4 . . . 1 3 5 >>> 5 1 5 2 4 6 >>> 6 2 6 . . . 1 3 5 >>> >>> Until know I only have created a loop that generates this additional >>> variables, but I did not figured out how to disriminate between the >>> two type. Can anyone hive me a hint? >>> >>> Kind regards, >>> Toby. >>> * >>> * 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/ >> > > * > * 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/

**References**:**st: Data Management Loop***From:*Toby <spiegeldesaster@googlemail.com>

**Re: st: Data Management Loop***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Data Management Loop***From:*Toby <spiegeldesaster@googlemail.com>

- Prev by Date:
**st: Quantile regression with IV** - Next by Date:
**Re: st: Quantile regression with IV** - Previous by thread:
**Re: st: Data Management Loop** - Next by thread:
**Re: st: Data Management Loop** - Index(es):