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 at the end of May, 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   "Victor Zammit" <vmz@go.net.mt>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re:number of occurences
Date   Sun, 1 Apr 2012 19:34:14 +0200

Yes,indeed,having to type out all occurences,was tedious, error prone and confidence shattering.The feedback that I received on the model problem/toy problem,enlightened me as to locating expences towards a particular activity,from a list of some nine hundred short explanations of types of expences ,that never exceed 25 strings,words or symbols.over a one year period.I must say that in cases where the symbol "-" was present,I used filefilter ,to distinguish particular tracing word,that identified the particular expence. I resolved it by :

drop _all

input str10 a1 str10 a2 .......str10 a25

(some nine hundred lines of explanations of types of expences,after filefilter)

end

save a,replace

forvalues i = 1/25 {

use a,clear

keep if a`i'=="identifier"

save a`i',replace

}

use a1,clear

forvalues i = 2/25 {

append using a`i'.dta

}

save a_a,replace

That gives me all the occurences towards the particular expence .

I used merge to verify the type of expences, Summed the amounts and voila.

Thanks for all the feedback that I received,and to life after Stata.

Victor Zammit.

----- Original Message ----- From: "Nick Cox" <njcoxstata@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Sunday, April 01, 2012 10:07 AM
Subject: Re: st: Re:number of occurences


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 <njcoxstata@gmail.com> 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 <eric.a.booth@gmail.com> 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
ebooth@ppri.tamu.edu
+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/

*
*   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