Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RE: RE: RE: st: panel data- assigning rank by country and year- THANKS


From   [email protected]
To   [email protected]
Subject   Re: RE: RE: RE: st: panel data- assigning rank by country and year- THANKS
Date   Fri, 16 Jan 2009 12:16:35 +1000

Thanks Nick, this works now.
Best wishes
Allison

----- Original Message -----
From: Nick Cox <[email protected]>
Date: Friday, January 16, 2009 9:41 am
Subject: RE: RE: RE: st: panel data- assigning rank by country and year- EXAMPLE
To: [email protected]

> So in what you said previously "within" countries and "within" 
> years had
> quite different meanings. 
> 
> What you want looks more like 
> 
> gen byte good = !missing(year, Country, var) & (var > 0) 
> bysort good Country : egen rank_var = rank(var)
> 
> Nick 
> [email protected] 
> 
> [email protected]
> 
> this is an example of what I mean....
> Within var1 I wish to rank countries (I have provided an example 
> of 2
> below) on that specific variable within that year. 
> Thank you, and once again, thanks so much for your attention to 
> this...
>                                 VAR1                       VAR2
> 
> Belize 1995 298700000.00 15.764373
> Belize 1996 308400000.00 17.196754
> Belize 1997 312300000.00 11.364923
> Belize 1998 331100000.00 5.5330906
> Belize 1999 365400000.00 -0.29874134
> Belize 2000 399100000.00 -6.1305733
> Belize 2001 433500000.00 -11.962405
> Belize 2002 446900000.00 -17.794237
> Belize 2003 457600000.00 -23.626069
> Belize 2004 540800000.00 -29.457901
> Belize 2005 574800000.00 -35.289733
> Belize 2006 598700000.00 -41.121565
> Brazil 1980 110900000000.00 -0.64295287
> Brazil 1981 124500000000.00 -0.5691551
> Brazil 1982 133200000000.00 -0.49535733
> Brazil 1983 95930000000.00 -0.42155956
> Brazil 1984 98600000000.00 -0.34776179
> Brazil 1985 105000000000.00 -0.27396402
> Brazil 1986 125700000000.00 -0.20016625
> Brazil 1987 138200000000.00 -0.12636848
> Brazil 1988 155900000000.00 -0.05257071
> Brazil 1989 199700000000.00 0.02122706
> 
> From: Nick Cox <[email protected]>
> 
> > Your ranks will not exceed 1 if you have at most one 
> observation 
> > for each combination of country and year, regardless of 
> > validity. 
> > 
> > I understood from your postings that you seek rankings within 
> > cross-combinations of country and year. That would be futile 
> if 
> > your data are defined uniquely by country and year. 
> > 
> > You should show us a segment of your data if this is not 
> clear. 
> > Do bear in mind that we rely entirely on what you say. 
> > 
> > [email protected]
> > 
> > Thanks Nick, this is now excluding the values less than 0. 
> > However, it appears to be assigning all the positive values as 
> > "1" as opposed to ranking them in order "1,2,3,4...." Am I 
> doing 
> > something wrong?
> > 
> > ----- Original Message -----
> > From: Nick Cox <[email protected]>
>  
> > > I don't know what "does not seem to work" means in your 
> case, 
> > > but one way forward is something like this. 
> > > 
> > > First, segregate observations that are good and bad for your 
> > > purpose. Let's say "good" observations are non-missing on 
> > these 
> > > variables and positive on -var-. 
> > > 
> > > gen byte good = !missing(year, Country, var) & (var > 0) 
> > > 
> > > Second, 
> > > 
> > > bysort good Country year : egen rank_var = rank(var) 
> > > 
> > > Third, use only 
> > > 
> > > ... if good 
> 
> > > [email protected]
> > > 
> > > Further to my query below:
> > > I just found that I have a number of missing and negative 
> > > values. Is there anyway I can exclude these cases when I 
> > assign 
> > > the country ranks?
> > > 
> > > [email protected]
> > > 
> > > > I am trying to assign ranks to country observations within 
> > > > years. By this I mean that I want to assign a score for 
> each 
> > > > observation (within a country) within that specific year. 
> > > > So far, I have calculated:
> > > > egen rank_var = rank(var) ---- this seems to provide ranks 
> > to 
> > > > countries, but does not take into account yearly 
> changes.  
> > > > I tried: 
> > > > bysort year Count: egen rank_var= rank(var)--- but this 
> does 
> > > not 
> > > > seem to work either. Is this something to do with 
> > > subscripting? 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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