Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Steve Nakoneshny <scnakone@ucalgary.ca> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Re:number of occurences |
Date | Fri, 30 Mar 2012 15:25:57 -0600 |
Hi Victor, In the absence of any additional description of your data, I will assume that these are strings in a single variable. I'm sure other will have different ways of doing this, but at first glance I would be inclined to use -regexm- to create a series of dummies for whether or not that color appears in a given string. -cond- and -inlist- may also be useful, but I have limited exposure to either of those. You can then use -tab- to get a summary of each color. For example: foreach foo in newlist red white brown orange black pink grey yellow green { gen `foo'=0 replace `foo'=1 if regexm(varname, `"foo"') tab `foo',m } Steve On 2012-03-30, at 3:10 PM, Victor Zammit 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/