[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Jann, Ben" <ben.jann@soz.gess.ethz.ch> |

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

Subject |
st: RE: Finding 3 most popular responses to a question |

Date |
Fri, 26 Nov 2004 09:14:13 +0100 |

-mrtab- on SSC might help. Type . ssc install mrtab to download the program. Then type . mrtab concern1-concern3, poly response(1/6) countall sort in order to see a table of counts for the 6 categories. It is also possible to save count variable for the individual categories: . mrtab concern1-concern3, poly response(1/6) countall /// generate(C) will produce 6 variables C1-C6 which can then be further processed by applying . collapse ..., by(VID) A solution to deal with ties would be to apply -mrtab- repeatedly: first to concern1-concern3, then to concern1-concern2, then to concern1 (or just use -tabulate- for the last step). Cheers, ben > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of > Farooq Naseer > Sent: Friday, November 26, 2004 6:55 AM > To: statalist@hsphsun2.harvard.edu > Subject: st: Finding 3 most popular responses to a question > > > Dear all, > > A randomly selected group of people within some survey > villages were given the > option to pick their top three every-day concerns: Of the six coded > options available, a respondent could pick, say, (4,4,2) and another > one in the same village could pick (1,6,5). (Duplicates like 4,4,.. > occur due to the fact that the responses were post-coded into six > broad categories to make analysis simpler). > > Now i want to get a measure for the community's top three priorities > by aggregating the information contained in the above individual > responses. > > I have the above info in a stata dataset as variables: > concern1-concern3. To avoid complications re. appropriate weighing > scheme, for the time being, I just want to take an unweighted count of > the values in these 3 variables for each village -- the variable VID > -- in my sample. In case there is a tie, for instance a village 'j' > has 20 responses each for values 4 and 6, I want to pick the value > which gets mentioned more in a higher-priority variable acc. to the > following priority ranking: concern1 > concern2 > concern3. > > I know it should be straight-forward to handle in Stata. But after > having spent some on it, and seeking help from Stata's Programming > manual, the program I produced is not working correctly and is quite > inelegant in its use of all the nested loops. I attach the program, as > is, below. Any help will be (greatly)^greatly appreciated! > > Thanks! > Farooq > > ************** > set trace on > set more off > > bysort VID: gen N = _N > > local j = 1 > local i = 0 > > while `j' < _N { > > local s1_x1=0 > local s1_x2=0 > *... likewise i define a total of 18 such local macros -- s1_x1 - > s3_x6 -- to tempo-*rarily store the count for all 6 options in each of > the three concern vars. > *... > forvalues k=1(1)3 { > local i = `j' > while `i' < `j'+N[`i'] { > if concern`k' == 1 in `i' { > local s`k'_x1 = `s`k'_x1' + 1 > } > else if concern`k' == 2 in `i' { > local s`k'_x2 = `s`k'_x2' + 1 > } > * removed similar else if statements for concern`k'==3, 4, 5 > & 6 to save space > *... > else { > * do nothing > display "Missing Value, Do Nothing" > } > local i = `i' + 1 > } > } > > * Now i have the count for all occurences of concern by value in each > of the top 3 concerns. Need to take an unweighted sum to get top 3 and > resolve ties. > > local s_x1 = `s1_x1'+`s2_x1'+`s3_x1' > local s_x2 = `s1_x2'+`s2_x2'+`s3_x2' > * and so on... until s_x6... > > local j = `j' + N[`i'] > } > *- the outer j while loop > * haven't finished the entire program yet but the results so far don't > seem correct... > > set trace off > set more on > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: Finding 3 most popular responses to a question** - Next by Date:
**st: RE: RE: Parsing not-quite-standard syntax** - Previous by thread:
**st: Finding 3 most popular responses to a question** - Next by thread:
**st: RE: RE: Parsing not-quite-standard syntax** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |