Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Re:number of occurences


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Re:number of occurences
Date   Sun, 1 Apr 2012 09:07:01 +0100

Also, it is a fair guess that Victor's problem is a toy problem. In a
real problem having to type out all the possibilities that occur could
be tedious and error-prone. Better to let Stata tell you what they
are.

On Sun, Apr 1, 2012 at 9:04 AM, Nick Cox <[email protected]> wrote:
> As so often happens on this list, I don't recommend regex machinery
> here when simpler methods will suffice.
>
> Here is yet another way to approach this:
>
> . input str80 mystr
>
>
>         mystr
>  1. red-white-brown-orange-black-pink-blue
>  2. grey-orange-white-red-yellow-blue
>  3. grey-yellow-blue-black-white-green
>  4. black-pink-orange-blue-grey-white
>  5. grey-green-yellow-white-red-pink
>  6. black-pink-orange-grey-white-red
>  7. grey-white-black-blue-brown-pink
>  8. grey-pink-blue-black-red-green
>  9. grey-green-black-blue-brown-orange
>  10. black-grey-brown-yellow-orange-pink
>  11. red-white-yellow-blue-black-green-brown
>  12. black-pink-grey-blue-green-white
>  13. grey-green-black-brown-yellow-pink
>  14. grey-black-red-blue-yellow-green
>  15. grey-blue-red-orange-yellow-black
>  16. red-white-green-pink-black-orange-grey
>  17. grey-black-pink-orange-yellow-brown
>  18. black-white-green-pink-grey-red
>  19. grey-green-orange-pink-red-yellow
>  20. black-grey-red-green-yellow-orange
>  21. end
>
> . compress
> mystr was str80 now str39
>
> . split mystr, p(-)
> variables created as string:
> mystr1  mystr2  mystr3  mystr4  mystr5  mystr6  mystr7
>
> . tabm mystr?, trans
>
>           |                                   variable
>    values |    mystr1     mystr2     mystr3     mystr4     mystr5
> mystr6     mystr7 |     Total
> -----------+-----------------------------------------------------------------------------+----------
>     black |         6          2          3          2          3
>     1          0 |        17
>      blue |         0          1          2          6          0
>     1          1 |        11
>     brown |         0          0          2          1          2
>     1          1 |         7
>     green |         0          4          2          1          1
>     4          0 |        12
>      grey |        11          2          1          1          2
>     0          1 |        18
>    orange |         0          1          3          3          1
>     3          0 |        11
>      pink |         0          4          1          3          0
>     5          0 |        13
>       red |         3          0          3          1          3
>     2          0 |        12
>     white |         0          5          1          1          2
>     2          0 |        11
>    yellow |         0          1          2          1          6
>     1          0 |        11
> -----------+-----------------------------------------------------------------------------+----------
>     Total |        20         20         20         20         20
>    20          3 |       123
>
>
> Here -tabm- is from -tab_chi- (SSC).
>
> Nick
>
> On Sat, Mar 31, 2012 at 8:13 PM, Eric Booth <[email protected]> wrote:
>> <>
>>
>> In addition to previous advice, see the package -moss- from SSC (type -findit moss-).
>>
>> - Eric
>>
>> __
>> Eric A. Booth
>> Public Policy Research Institute
>> Texas A&M University
>> [email protected]
>> +979.845.6754
>>
>> On Mar 30, 2012, at 4: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
>>>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index