Statalist


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

Re: AW: st: data management


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: AW: st: data management
Date   Mon, 07 Dec 2009 16:44:39 +0100

Ups. yes.

You can do it by hand, then

. gen index = _n
. reshape long Var, i(index)
. by index Var, sort: gen countdif = 1 if _n==1
. by index: replace countdif = sum(countdif)
. by index: replace countdif = coundif[_N]
. reshape long 
 





Am Montag, den 07.12.2009, 16:02 +0100 schrieb Martin Weiss:
> <> 
> 
> 
> 
> *************
> egen, group()
> *************
> 
> does not support -by-, though...
> 
> 
> HTH
> Martin
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von Ulrich Kohler
> Gesendet: Montag, 7. Dezember 2009 16:04
> An: [email protected]
> Betreff: Re: st: data management
> 
> I would use egen-group in the long format for this:
> 
> . gen index = _n
> . reshape long Var, i(index)
> . egen countdif = group(Var), by(index)
> . reshape long 
> 
> Many regards
> Uli
> 
> Am Montag, den 07.12.2009, 15:56 +0100 schrieb [email protected]:
> > Dear all,
> > I have a quick data management question. I would like to count the number of different values over several variables within a row and save the result in a new variable.
> > 
> > For example: 
> > Var1 Var2 Var3 Var4 Var5 Var6 Var7 Varx
> > 1         2      3        9       20     1       1      ...
> > 
> > In the example above, the new variable would holds the value 5, since Var1, Var6 and Var7 all hold the same value (put differently, 5 different values can be count over var1 - var7). 
> > 
> > I tried the following command: egen byte countdif = diff(var1 var2 var3 var4 var5 var6 var7 varx). However, the new variable is only a dummy (0/1). 
> > 
> > I bet there is a very simple solution – however I am too blind to see it…
> > 
> > I appreciate any help and suggestions.
> > Thanks
> > Simon
> > 
> > 
> > 
> > *
> > *   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index