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/