I am not clear whether you have learned
Stata programming or just intend to,
but the advice is the same:
In a word, -reshape-.
Doing it across rows is tricky even for Stata users
with some programming experience. -reshape-
and exploiting the power of -by:- is
the way to go. Anything else is the equivalent
of climbing the Eiger North Face in winter,
feet first, when you could go round by the
railway.
Nick
[email protected]
Farooq Naseer
> I got some useful hints on my last posting of this question (detailed
> problem description attached below) but since at that time i hadn't
> learned programming, I just manually entered the top 3 concerns after
> generating village-level counts using -mrtab-.
>
> The trouble is that the data has changed since then, finally
> convincing me to learn Stata programming! However, having experience
> with the C++ way of doing things i find it hard to grasp how one could
> do this without using arrays.
>
> The problem essentially is that I have three lists of count data
> (corresponding to the values taken by 3 sets of variables - c1-c6,
> d1-d6, e1-e6). For each observation in the data, I want to sort c1-c6
> according to size and pick three variables with the highest count. I
> need to refer to the values stored in d1-d6 (and to e1-e6, if needed)
> _only_ if i need to break any ties in the ranking of c1-c6.
>
> So, for instance, if the values taken by the variables (generated by
> -mrtab-) are as follows:
>
> Obs # c1 c2 c3 c4 c5 c6 d1 d2 d3 d4 d5 d6 e1
> e2 e3 e4 e5 e6
> 21. 1 0 6 2 3 3 0 0 2 1 2 2
> 0 0 1 0 0 1
>
> So in this case we see that based on c1-c6 we can sort (3, 5, 6, ...)
> but we need to break the tie between option 5 and 6 since both are
> three. We then look at d5 and d6, but they are also tied both with
> value 2. So then we look at e5 and e6, and choose 6 as the second
> highest ranked option as compared to 5 (in case we can't even break
> the tie in the e-list; I just assign ranks randomly). Note that the
> variables were generated in such a way that, for all n, c1>=d1>=e1.
>
> So for observation 21, the top 3 concerns based on the above
> data would 3, 6, 5.
>
> I am clueless on how to do this in Stata.
> Any help, general comments or specific suggestions, will be
> much appreciated!
>
> farooq
>
>
> ---------- Forwarded message ----------
> From: Farooq Naseer <[email protected]>
> Date: Fri, 26 Nov 2004 00:55:17 -0500
> Subject: Finding 3 most popular responses to a question
> To: [email protected]
>
>
> 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.
>
> <snip>...
*
* 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/