Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Re:number of occurences


From   "Dimitriy V. Masterov" <dvmaster@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re:number of occurences
Date   Fri, 30 Mar 2012 17:25:56 -0400

I am assuming that your list is stores in a variable called list. As
long as a color appears once per row, this should work:

foreach color in red white brown orange black pink blue grey yellow green {;
		gen `color'=cond(regexm(list,"`color'")==1,1,0);	
};

If you want a total for the list as a whole:
collapse (sum) red-green;

On Fri, Mar 30, 2012 at 5:10 PM, Victor Zammit <vmz@go.net.mt> wrote:
> Dear Statalist,
>
> the following sample contains ten different colors:red,white,brown,orange,
>
> black,pink,blue,grey,yellow,green,in all.Given a much bigger sample,
>
> how can I find out the number of occurences for each of the ten colors.
> red-white-brown-orange-black-pink-blue
> grey-orange-white-red-yellow-blue
> grey-yellow-blue-black-white-green
> black-pink-orange-blue-grey-white
> grey-green-yellow-white-red-pink
> black-pink-orange-grey-white-red
> grey-white-black-blue-brown-pink
> grey-pink-blue-black-red-green
> grey-green-black-blue-brown-orange
> black-grey-brown-yellow-orange-pink
> red-white-yellow-blue-black-green-brown
> black-pink-grey-blue-green-white
> grey-green-black-brown-yellow-pink
> grey-black-red-blue-yellow-green
> grey-blue-red-orange-yellow-black
> red-white-green-pink-black-orange-grey
> grey-black-pink-orange-yellow-brown
> black-white-green-pink-grey-red
> grey-green-orange-pink-red-yellow
> black-grey-red-green-yellow-orange
>
> Thanks for any feedback,
>
> Victor Zammit.
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index