Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: RE: Labeling Min and Max Values


From   "Eric Booth" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Labeling Min and Max Values
Date   Fri, 5 Mar 2010 17:26:10 -0600

>
I interpreted Lauren's question differently than Martin-though I'm still not certain exactly how Lauren want's her output broken down.  Here it is using Martin's example and -tabout- to get the max and min growth by country (across all years) and by country & year:


*******
clear*
set obs 50
gen byte country=_n

la def coun ///
1       "Afghanistan     " ///          
2       "Albania         " ///          
3       "Algeria         " ///          
4       "Andorra         " ///          
5       "Angola          " ///          
6       "Anguilla        " ///          
7       "Antarctica      " ///          
8       "Argentina       " ///          
9       "Armenia         " ///          
10      "Aruba          " ///          
11      "Australia      " ///          
12      "Austria        " ///          
13      "Azerbaijan     " ///          
14      "Bahrain        " ///          
15      "Bangladesh     " ///          
16      "Barbados       " ///          
17      "Bassas da India" ///          
18      "Belarus        " ///          
19      "Belgium        " ///          
20      "Belize         " ///          
21      "Benin          " ///          
22      "Bermuda        " ///          
23      "Bhutan         " ///          
24      "Bolivia        " ///          
25      "Bosnia and Herzegovina        " ///          
26      "Botswana       " ///          
27      "Bouvet Island  " ///          
28      "Brazil         " ///          
29      "British Indian Ocean Territory" ///          
30      "British Virgin Islands        " ///          
31      "Brunei         " ///          
32      "Bulgaria       " ///          
33      "Burkina Faso   " ///          
34      "Burma          " ///          
35      "Burundi        " ///          
36      "Cambodia       " ///          
37      "Cameroon       " ///          
38      "Canada         " ///          
39      "Cape Verde     " ///          
40      "Cayman Islands " ///          
41      "Central African Republic      " ///          
42      "Chad           " ///          
43      "Chile          " ///          
44      "China          " ///          
45      "Christmas Island              " ///          
46      "Clipperton Island             " ///          
47      "Cocos          " ///
48      "Colombia       " ///          
49      "Comoros        " ///          
50      "Cook Islands   " ///              


la val country coun
expand 5
bys country: gen year= 2000 + _n

gen growth=rnormal(.01,.03)


**across all years**
tabout country year using "test.xls", replace sum c(min growth max growth) /*
  */  h2(min/max by country and year) npos(lab) nlab((n=#)) lines(double) f(5c)

**by year for each country**
	cap erase "test_byyear.xls"
forval y = 2001/2005 {
	tabout country  if year==`y' using "test_byyear.xls", append sum c(min growth max growth) /*
   */     h3(min/max by country in `y') npos(lab) nlab((n=#)) lines(double) f(5c)
}
********

You could sort these lists, but if you want to constrain the list to the max growth rate by country, by year, or by both country and year, you could create an indicator, similar to Martin's example, for the min and the max and then in the -tabout- command above  just include an "if" statement, so add this to the code above:

**
bys year: egen locmax=max(growth)
bys year: egen locmin=min(growth)

bys year: gen min=1 if growth==locmin
bys year: gen max= 1 if growth == locmax

*w/tabstat:
tabstat growth if min==1, by(country) stat(min)
tabstat growth if max==1, by(country)  stat(max)

**across all years**
cap erase "test2_min.xls"
cap erase "test2_max.xls"

foreach v in min max {
forval y = 2001/2005 {
tabout country if `v'==1 & year==`y' using "test2_`v'.xls", sum append c( `v' growth ) /*
*/  f(5c) h3(`v' by country for year `y') npos(lab) nlab((n=#)) lines(double)
    }
 }
**


__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
+979.845.6754




-----Original Message-----
From: [email protected] on behalf of Martin Weiss
Sent: Fri 3/5/2010 3:32 PM
To: [email protected]
Subject: st: RE: Labeling Min and Max Values
 

<>

You might even end up using -list- for this purpose:


*******
clear*
set obs 50
gen byte country=_n

la def coun ///
1	"Afghanistan                    " ///           
2	"Albania                        " ///           
3	"Algeria                        " ///           
4	"Andorra                        " ///           
5	"Angola                         " ///           
6	"Anguilla                       " ///           
7	"Antarctica                     " ///           
8	"Argentina                      " ///           
9	"Armenia                        " ///           
10	"Aruba                         " ///           
11	"Australia                     " ///           
12	"Austria                       " ///           
13	"Azerbaijan                    " ///           
14	"Bahrain                       " ///           
15	"Bangladesh                    " ///           
16	"Barbados                      " ///           
17	"Bassas da India               " ///           
18	"Belarus                       " ///           
19	"Belgium                       " ///           
20	"Belize                        " ///           
21	"Benin                         " ///           
22	"Bermuda                       " ///           
23	"Bhutan                        " ///           
24	"Bolivia                       " ///           
25	"Bosnia and Herzegovina        " ///           
26	"Botswana                      " ///           
27	"Bouvet Island                 " ///           
28	"Brazil                        " ///           
29	"British Indian Ocean Territory" ///           
30	"British Virgin Islands        " ///           
31	"Brunei                        " ///           
32	"Bulgaria                      " ///           
33	"Burkina Faso                  " ///           
34	"Burma                         " ///           
35	"Burundi                       " ///           
36	"Cambodia                      " ///           
37	"Cameroon                      " ///           
38	"Canada                        " ///           
39	"Cape Verde                    " ///           
40	"Cayman Islands                " ///           
41	"Central African Republic      " ///           
42	"Chad                          " ///           
43	"Chile                         " ///           
44	"China                         " ///           
45	"Christmas Island              " ///           
46	"Clipperton Island             " ///           
47	"Cocos                         " ///
48	"Colombia                      " ///           
49	"Comoros                       " ///           
50	"Cook Islands                  " ///               


la val country coun

expand 5
bys country: gen byte year=_n

gen growth=rnormal(.01,.03)

bys year: egen locmax=max(growth)
by year: egen locmin=min(growth)

bys year (growth): gen byte min=_n==1
by year (growth): gen byte max=_n==_N

la def max 0 "" 1"max"
la def min 0 "" 1 "min"
la val max max
la val min min

replace locmax=. if min
replace locmin=. if max

li year country max min locmax locmin /* 
 */  if min | max, sepby(year) noo
*******


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of e. lauren
Sent: Freitag, 5. März 2010 21:15
To: [email protected]
Subject: st: Labeling Min and Max Values


Hi all:

 

A pretty straightforward question, but how does one label corresponding Min
and Max values (using tabout or another tabulate command).

 

Let's say I have a list of 50 countries and corresponding GDP growth rates,
over time.  I would like to use tabout to label the local minimums and
maximums, and indicate the corresponding country name for each given year. 

 

Any tips on how to set this up?

 

Many thanks,
Lauren
*
*   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/

<<winmail.dat>>



© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index