Professional Documents
Culture Documents
Gráficos Con Stata PDF
Gráficos Con Stata PDF
Gráficos Con Stata PDF
Dawn Koffman
Office of Population Research
Princeton University
September 2015
Stata 14 Graphics
Pros:
Many graph types and plot types provided
Multiple plot types may be overlaid
Can easily change overall look of graphs
Same options available for most types of graphs
Very flexible
Cons:
Sometimes slow
Large syntax: 731 page graphics manual!
Stata 14 Graphics Manual is only available on-line:
Help -> PDF Documentation -> [G] Graphics
/* OR */
50
70
life expectancy
60
80
40
/* OR */
line le year
1900
1920
1940
1960
1980
2000
Year
80
40
50
life expectancy
60
70
Using Schemes
1900
1920
1940
1960
1980
2000
Year
80
60
life expectancy
70
50
1900
1920
1940
1960
1980
40
2000
Year
30
40
50
60
70
80
1900
1920
1940
1960
1980
2000
Year
Life expectancy, white males
Life expectancy, black males
Adding Text
40
50
60
70
80
30
1920
1940
1960
1980
2000
Year
Life expectancy, white males
Life expectancy, black males
twoway ///
(scatter le year if year >= 1950) ///
(lfit
le year if year >= 1950)
74
72
/* OR */
70
scatter ///
le year if year >= 1950 ///
|| lfit le year if year >= 1950
76
/* OR */
#delimit
twoway
(scatter
(lfit
#delimit
68
/* OR */
1950
1960
1970
life expectancy
Year
1980
1990
2000
Fitted values
1925
///
1925 & ///
1950
///
1950
75
65
60
///
>= 1925) ///
>= 1925 & ///
< 1950) ///
>= 1950)
55
twoway
(scatter le year if year
(lfit
le year if year
year
(lfit
le year if year
70
/* OR */
/* OR */
1920
#delimit ;
scatter le year if year >= 1925
|| lfit le year if year >= 1925 & year < 1950
|| lfit le year if year >= 1950;
#delimit cr
1940
1960
Year
life expectancy
Fitted values
1980
2000
Fitted values
75
70
65
#delimit cr
80
1950
1960
1970
1980
1990
2000
Year
Life expectancy, males
Fitted values
10
75
80
#delimit ;
scatter le_male le_female year if year >= 1950
|| lfit le_male
year if year >= 1950
|| lfit le_female year if year >= 1950
,title("US Male and Female Life Expectancy, 1950-2000")
text(75 1978 "Female", place(3))
text(68 1978 "Male", place(3))
legend(off);
US Male and Female Life Expectancy, 1950-2000
#delimit cr
70
Female
65
Male
1950
1960
1970
1980
Year
1990
2000
11
80
50
Linear fit
20
40
60
80
Percent of population with access to safe water
95% CI
100
12
North America
Canada
CubaPuerto Rico
Jamaica
Panama
Trinidad and Tobago
Mexico
Dominican Republic
El Salvador Honduras
Nicaragua
Guatemala
Haiti
50
Linear fit
20
40
60
80
Percent of population with access to safe water
95% CI
100
13
North America
Canada
Cuba
Panama
Jamaica
Puerto Rico
Mexico
Nicaragua
Guatemala
50
Haiti
Linear fit
95% CI
100
14
Canada
CubaPuerto Rico
Chile
Panama
Uruguay
Argentina
Venezuela
Trinidad and Tobago
Mexico
Dominican Republic
Ecuador Colombia
El SalvadorHonduras
Peru
Nicaragua
Brazil
Jamaica
Paraguay
Guatemala
55
Bolivia
Haiti
20
40
60
80
Percent of population with access to safe water
100
15
and
Legend Display
Position of Marker
Labels
Canada
Puerto Rico
Cuba
Jamaica
Chile
Panama
Uruguay
Argentina
Venezuela
Trinidad and Tobago
Mexico
Dominican Republic
Paraguay
Ecuador
Colombia
El Salvador
Honduras
Peru
Nicaragua
Brazil
Guatemala
Bolivia
55
North America
replace pos = 9 if country == "Argentina"
South America
Haiti
replace pos = 9 if country == "Canada"
replace pos = 9 if country == "Cuba"
20
40
60
80
100
replace pos = 9 if country == "Panama"
Percent of population with access to safe water
replace pos = 9 if country == "Venezuela"
replace pos = 9 if country == "Jamaica"
replace pos = 9 if country == "Dominican Republic"
replace pos = 9 if country == "Ecuador"
replace pos = 9 if country == "El Salvador"
replace pos = 12 if country == "Puerto Rico"
#delimit ;
twoway
(scatter lexp safewater if region == 2
,mlabel(country) mlabvposition(pos))
(scatter lexp safewater if region == 3
,mlabel(country) mlabvposition(pos))
,title("Life expectancy at birth by access to safe water, 1998")
subtitle("North and South America")
ytitle("Life expectancy at birth")
xtitle("Percent of population with access to safe water")
legend(ring(0) pos(5) order(1 "North America" 2 "South America") cols(1));
16
#delimit cr
Puerto Rico
Cuba
Chile
Panama
Uruguay
Argentina
Venezuela
Trinidad and Tobago
Mexico
Dominican Republic
Paraguay
Ecuador
Colombia
El Salvador
Honduras
Peru
Nicaragua
Brazil
Jamaica
Guatemala
55
Bolivia
Haiti
20
North America
South America
North America linear fit
South America linear fit
40
60
80
Percent of population with access to safe water
100
17
Puerto Rico
Cuba
Chile
Panama
Uruguay
Argentina
Venezuela
Trinidad and Tobago
Mexico
Dominican Republic
Paraguay
Ecuador
Colombia
El Salvador
Honduras
Peru
Nicaragua
Brazil
Jamaica
Guatemala
55
Bolivia
Haiti
20
North America
South America
North America linear fit
South America linear fit
40
60
80
Percent of population with access to safe water
100
18
60
50
Total
60
70
80
S.A.
50
70
80
#delimit ;
twoway scatter lexp safewater, by(region, total)
,ytitle("Life expectancy at birth")
xtitle("Percent of population with access to safe
water");
#delimit cr
Eur & C.Asia
N.A.
20
40
60
80
100 20
40
60
80
100
19
By-Graph Options
twoway scatter lexp safewater
,by(region,total style(compact)
title("Life expectancy by access to safe water") note(""))
ytitle("Life expectancy at birth")
xtitle("Percent of population with access to safe water");
Life expectancy by access to safe water
N.A.
S.A.
Total
60
50
80
70
60
50
70
80
20
40
60
80
10020
40
60
80
100
20
N.A.
S.A.
Total
80
75
70
65
60
55
80
75
70
65
60
55
30
40
50
60
70
80
90
100
30
40
50
60
70
80
90
100
21
80
Canada
Puerto Rico
Cuba
75
Jamaica
Panama
Trinidad and Tobago
Mexico
Dominican Republic
70
El Salvador
Honduras
65
Nicaragua
Guatemala
60
55
Haiti
20
40
60
80
Percent of population with access to safe water
100
22
Chile
Uruguay
Argentina
70
Paraguay
Venezuela
Ecuador
Colombia
Peru
Brazil
65
Bolivia
60
40
50
60
70
80
Percent of population with access to safe water
90
23
Combining Graphs
graph combine north_america south_america
,title("Life expectancy by access to safe water", color(black)) col(1);
North America
80
75
Canada
Puerto Rico
Cuba
Panama
Trinidad
Mexico and Tobago
Jamaica
70
El Salvador
Dominican Republic
Nicaragua
Honduras
Guatemala
65
60
55
Haiti
20
40
60
80
Percent of population with access to safe water
100
South America
75
Chile
Argentina
70
Paraguay
Venezuela
Ecuador
Uruguay
Colombia
Peru
Brazil
65
Bolivia
60
40
50
60
70
Percent of population with access to safe water
80
90
24
Canada
75
Jamaica
Dominican Republic
70
Puerto Rico
Cuba
Nicaragua
Honduras
Guatemala
60
55
Haiti
20
Graphs
Panama
Trinidad and Tobago
Mexico
El Salvador
65
Combining
40
60
80
Percent of population with access to safe water
100
South America
80
75
Argentina
70
Paraguay
Venezuela
Ecuador
Chile
Uruguay
Colombia
Peru
Brazil
65
Bolivia
60
55
20
40
60
80
Percent of population with access to safe water
100
25
26