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

Re: st: Tactical looping


From   "Clive Nicholas" <Clive.Nicholas@newcastle.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Tactical looping
Date   Mon, 26 Jan 2004 13:36:14 -0000 (GMT)

Nick and Michael,

Thanks to both of you for your sterling help.

C.

> In other contexts, when preserving names
> is not important, -rowsort- from SSC would
> suffice, but here who came where is crucial
> and so I concur strongly on -reshape-.
>
> There is a very similar example to Clive's
> within
> http://www.stata.com/support/faqs/data/reshape3.html
>
> Nick
> n.j.cox@durham.ac.uk
>
> Michael Blasnik replied to Clive Nicholas:
>
>> I think this calls for a reshape, for example :
>>
>> use mydata
>> reshape long @pc, i(id) j(party) string
>> bysort id (pc): gen byte rank=_N-_n+1
>> keep if rank<4
>> keep id party rank
>> reshape wide  party, i(id) j(rank)
>> sort id
>> save top3
>> use mydata
>> sort id
>> merge id using top3
>> assert _merge==3
>>
>> This assumes your file is called mydata and that there is some sort of
>> election id variable, called id.  It keeps the top 3 as
>> party1 party2 and
>> party3.
>
>> > Some months ago, I posted a question about what code I
>> needed in order to
>> > generate dummy codes to indicate whether or not a candidate won a
>> constituency
>> > election. In my dataset, I needed to do this for 3456 cases across 6
>> > time-points.
>
>> on reading an old BJPS
>> article about the
>> > potential effects of tactical voting on consitituency
>> outcomes at general
>> > elections, I realised I'd made a quite stupid omission: I'd
>> coded the
>> winners,
>> > but _not_ the candidates who finished second and third!
>> >
>> > Looking at -help mathfun-, the only relevant operators here
>> are -max- and
>> > -min- (as far as I can tell). Obviously, -max- cannot be
>> used, and it
>> would be
>> > rather dicy to use -min- (since different parties finish in
>> different
>> places
>> > in different seats at different times). Therefore, is there
>> a solution?
>
> *
> *   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/
>


CLIVE NICHOLAS        |t: 0(44)191 222 5969
Politics Building     |e: clive.nicholas@ncl.ac.uk
School of Geography,  |f: 0(44)870 126 2421
 Politics & Sociology |
University of         |
 Newcastle-upon-Tyne  |
Newcastle-upon-Tyne   |
NE1 7RU		      |
United Kingdom	      |http://www.ncl.ac.uk/geps
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index