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

st: RE: Re: Tactical looping


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Tactical looping
Date   Sun, 25 Jan 2004 19:26:37 -0000

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 
[email protected] 

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/



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