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

Re: st: Another reshaping problem


From   Seb Buechte <[email protected]>
To   [email protected]
Subject   Re: st: Another reshaping problem
Date   Sat, 16 Apr 2005 19:42:35 +0200

Ok, I will it give a try...

taking your data expample the following will lead to the desired result:

// since alway two obs for within a group belong together and those two obs are
// identified by subsequent numbers as present in column "var"
// I would build a new subgroup-var, called grp2
// it builds a by-group of "group" ordered according to "var"

bysort group (var): gen grp2=round(_n/2,1)

// the dataset now looks like this:
// group      var      strategy
// group    var    strategy  grp2
// 1         11        0           1
// 1         12        1           1
// 1         13        0           2
// 1         14        1           2
// 2         15        0           1
// 2         16        1           1

// now you create a new groupvar using egen's group command

egen grp3=group(group grp2)

// now you can do a reshape

reshape wide  var, i(grp3) j(strategy)

// and order the variables

order  group var0 var1 grp2 grp3

// the dataset now looks like this:
// group    var0    var1  grp2    grp3
//     1	11	12	1	1
//     1	13	14	2	2
//     2	15	16	1	3

I hope this helps!

Kind regards,
sebastian

ps. personally I would be interested wether there are more
sophisticated approaches to the problem described by Sascha..

On 4/15/05, Sascha Robert <[email protected]> wrote:
> Hi
> 
> ...and sorry to hassle you again with a ridiculous problem. A teacher
> once told me: 'There are no dumb questions!', though. Well, there are,
> as the protagonists of 'Simple Life' have evidenced, and nontheless I
> try it:
> 
> My data in short:
> 
> group    var    strategy
> 1         11        0
> 1         12        1
> 1         13        0
> 1         14        1
> 2         15        0
> 2         16        1
> 
> If the first two rows would be omited,
> 
> . reshape wide var, i(group) j(strategy)
> 
> would do the trick. The problem is, using all observations, that
> multiple observations within 'group' share the same 'strategy'.
> 
> My data, after the reshaping, should look like this:
> 
> group    var0    var1
> 1         11         12
> 1         13         14
> 2         15         16
> 
> Note that my data is in a form that would not produce missing values in
> 'var0' and 'var1' (within a 'group' there is always an equal share of
> 'strategy' = 0 and 'strategy' = 1).
> 
> Can anybody help? Thankyou.
> Sascha
> 
> --
> ***** sascha robert | mailto: [email protected] *****
> *
> *   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/
> 


-- 
- Seb F Buechte
-
- Stay tuned!

*
*   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