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]

st: adding or counting values as an array


From   Daniel Exeter <d.exeter@auckland.ac.nz>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: adding or counting values as an array
Date   Thu, 6 Oct 2011 05:49:04 +0000

Hi there
In Stata 11 (win7, 64bit),  I have a dataset with quarterly observations of events from 2006 to 2011. 
Each field is named y2006_q1, y2006_q2 .. y2011_2

The data is dichotomous (0/1) and I want to know:
-for the entire period (q1 2006 to q3 2011)  and separately for each year
-	how many quarters each event was observed 
-	how many quarters each event was not observed 


is there an easy way to code something that would do this:

gen included = sum (yr20*) if yr20* ==1
gen excluded = count (yr20*) if  yr20* ==0

and

gen inc06 = sum (yr2006*) if yr2006 ==1 
gen exc06 = count(yr2006*) if yr2006 ==0

Cheers
Dan

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