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]

From |
Eric Booth <ebooth@ppri.tamu.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Table to count how many times an event occurs with another |

Date |
Thu, 4 Aug 2011 15:39:14 +0000 |

<> Sorry, I forgot to mention that -tuples- is a user-written package (by NJC) from SSC. Type -ssc install tuples- or -findit tuples- to install. - Eric __ Eric A Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu On Aug 4, 2011, at 10:34 AM, Eric Booth wrote: > <> > > Try: > > *********** > clear > input str12(Date Time ) D1 D2 D3 D4 > "01/01/2008" "8:00" 1 0 0 1 > "01/01/2008" "9:00" 0 1 0 0 > "01/01/2008" "10:00" 0 1 1 0 > "01/01/2008" "9:00" 0 0 0 0 > "01/01/2008" "10:00" 1 1 1 1 > "01/01/2008" "9:00" 0 1 0 1 > "01/01/2008" "10:00" 1 0 0 1 > end > > > **number of times each pair co-occurs: > tuples D1-D4, display max(2) > *tuples 5-10 are what you want: > forval i = 5/`ntuples' { > loc one: piece 1 2 of "`tuple`i''" > loc two: piece 2 2 of "`tuple`i''" > g myvar`i' = 1 if `one'==1 & `two'==1 > lab var myvar`i' "`tuple`i''" > } > > **count number of times in each Time interval: > preserve > collapse (count) myvar5-myvar10, by(Date Time) > l Time my*, noobs > restore > > *or you can use -egen count- > ********** > > - Eric > __ > Eric A Booth > Public Policy Research Institute > Texas A&M University > ebooth@ppri.tamu.edu > > On Aug 4, 2011, at 10:07 AM, Katia Bobulova wrote: > >> This is an example of my databse: >> >> Date Time D1 D2 D3 D4 >> 01/01/2008 8:00 1 0 0 1 >> 01/01/2008 9:00 0 0 0 0 >> 01/01/2008 10:00 0 1 1 0 >> ..... ....... . . . . >> >> For every day I have something similar to the above example with dummy >> variables. >> In the fist row (8:30) I have that two dummies happen at the same time >> and also in the last row (10:00). >> I want to construct a table, in which I have the number of times ( for >> each interval throughout my whole sample) I have that events D1 and D4 >> happen together and D2 and D3 happen together and so on for all >> possible combinations. >> >> Thanks, >> Katia >> >> >> >> >> >> 2011/8/4 Anders Alexandersson <andersalex@gmail.com>: >>> Please provide the original example data of the 4 events and 10 >>> observations from which you want to create the table. >>> The reason I ask is that I do not understand your provided 4*4 table. >>> >>> Anders Alexandersson >>> andersalex@gmail.com >>> >>> On Thu, Aug 4, 2011 at 10:08 AM, Katia Bobulova >>> <katia.bobulova@googlemail.com> wrote: >>>> Because it doesn't do what I want and anyway it is not possible to use >>>> tabulate with more than two variables. >>>> >>>> Katia >>>> >>>> 2011/8/4 Nick Cox <njcoxstata@gmail.com>: >>>>> Why not -tabulate-? >>>>> >>>>> Nick >>>>> >>>>> On 4 Aug 2011, at 10:52, Katia Bobulova <katia.bobulova@googlemail.com> >>>>> wrote: >>>>> >>>>>> Dear All, >>>>>> >>>>>> I have many events in my dataset and I want to count how many times >>>>>> one event happens with another one. >>>>>> >>>>>> Assuming fro example 4 events and ten observations, I would like to >>>>>> have a table like this: >>>>>> >>>>>> x1 x2 x3 x4 >>>>>> x1 10 2 1 3 >>>>>> x2 1 10 0 0 >>>>>> x3 0 3 10 1 >>>>>> x4 2 5 0 10 >>>>>> >>>>>> Could you please help me? >>> >>> * >>> * 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/ > > > * > * 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/

**References**:**st: Table to count how many times an event occurs with another***From:*Katia Bobulova <katia.bobulova@googlemail.com>

**Re: st: Table to count how many times an event occurs with another***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Table to count how many times an event occurs with another***From:*Katia Bobulova <katia.bobulova@googlemail.com>

**Re: st: Table to count how many times an event occurs with another***From:*Anders Alexandersson <andersalex@gmail.com>

**Re: st: Table to count how many times an event occurs with another***From:*Katia Bobulova <katia.bobulova@googlemail.com>

**Re: st: Table to count how many times an event occurs with another***From:*Eric Booth <ebooth@ppri.tamu.edu>

- Prev by Date:
**Re: st: Table to count how many times an event occurs with another** - Next by Date:
**Re: st: mfp and factor variable** - Previous by thread:
**Re: st: Table to count how many times an event occurs with another** - Next by thread:
**st: set mat size suggested larger than system max** - Index(es):