Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Finding 3 most popular responses to a question


From   Farooq Naseer <[email protected]>
To   [email protected]
Subject   st: Finding 3 most popular responses to a question
Date   Fri, 26 Nov 2004 00:55:17 -0500

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/



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