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]

st: sum of count using a loop


From   Keniajin Wambui <[email protected]>
To   [email protected]
Subject   st: sum of count using a loop
Date   Tue, 30 Jul 2013 17:12:31 +0300

I have a data set with a unique pid and a list of 32 variables with
the same suffix i.e maize_source, peas_source, sukuma_source,
cabbage_source.....
All the 32 variables have  option 1,2,3 or 4. I want to do a sum of
all the counts of each option for across all the variables using stata
12 on windows 7
i.e
option    total
1           4000
2             568
3          1200
4          14000

I am trying

foreach var of varlist  maize_source - peas_source {
count if `var'==1
    replace total=_N+_n if `var'==1
countif `var'==1
        }
but its giving a count with a wrong total

I will appreciate the support
-- 
Mega Six Solutions
Web Designer and Research Consultant
Kennedy Mwai
25475211786
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index