-
Notifications
You must be signed in to change notification settings - Fork 2
/
Stata_WCsyntax.do
152 lines (109 loc) · 3.88 KB
/
Stata_WCsyntax.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
set more off
set more off, permanently
set line 200
capture log close
log using Stata_WClog.smcl, replace
************************
**Load data set
*set working directory
cd "C:\Users\siebe\Documents\4 FMG\Coding Presentation"
*Import CSV & drop variables
import delimited using results.csv
save results.dta, replace
drop city country
*Check first few rows
list * in 1/10
*Check variables
describe
*Check missings (dots or ".")
findit mdesc
mdesc
*Subset dataset to only include Germany matches
keep if home_team=="Germany" | away_team=="Germany"
list * in 1/10
************************
**Recodes and Data Manpulation
*Simple recode (each observation equals 1)
gen match = 1
list * in 1/10
*Conditional recode (Define Goals Scored)
gen goals = home_score if home_team=="Germany"
replace goals = away_score if away_team=="Germany"
*Conditional recode (Define Goals Conceded)
gen conceded = away_score if home_team=="Germany"
replace conceded = home_score if away_team=="Germany"
list home_team away_team home_score away_score goals conceded in 921/931
*Simple recode (Define Goal Differential)
gen goaldiff = goals - conceded
list home_score away_score goals conceded goaldiff in 921/931
*Dummy recode (Define Friendly v Competitive match)
gen friendly = tournament == "Friendly"
list tournament friendly in 921/931
*Categorical recode (home vs away vs neutral matches)
gen home = "home" if home_team=="Germany"
replace home = "away" if away_team=="Germany"
replace home = "neutral" if neutral=="TRUE"
encode home, gen(home_num)
label list home_num
list home_team away_team neutral home home_num in 921/931
*Conditional recode (opponent)
gen opponent = away_team if home_team=="Germany"
replace opponent = home_team if away_team=="Germany"
list home_team away_team opponent in 921/931
*String variables (Define year)
gen year = substr(date,1,4)
destring year, replace
list date year in 921/931
*Drop redundant variables
drop home_score away_score tournament neutral home_team away_team
list * in 921/931
************************
**Descriptive Statistics
*Tabs
tab home friendly
*Unweighted proportions
prop home_num friendly
*Goal difference table
table home friendly, contents(mean conceded)
table home friendly, contents(mean goaldiff)
table home friendly, contents(mean goals)
*or*
forval frdly=0/1 {
foreach hme in away home neutral {
foreach var in conceded goaldiff goals {
local slabel: value label friendly
local vlabel: label `slabel' `frdly'
di as res _n "`var' if home is `hme' and friendly is `vlabel'"
mean `var' if home=="`hme'" & friendly==`frdly'
}
}
}
*Opponent table
mean goaldiff if opponent=="Korea Republic"
tab match if opponent=="Korea Republic"
************************
**Graphs
*Histogram
hist goaldiff, bin(25) freq ///
title(Histogram of Goal Differences) ///
ytitle(Count) xtitle(Goal Differential) ///
title(Histogram of Goal Differential)
*Line graphs
bysort year: egen m_goals = mean(goals)
twoway (line m_goals year, lcolor(green)), xlabel(1908(20)2018) ///
title(Goals Scored by Year)
bysort year: egen m_conceded = mean(conceded)
replace m_conceded = m_conceded*-1
twoway (line m_conceded year, lcolor(red)), xlabel(1908(20)2018) ///
title(Goals Conceded by Year)
bysort year: egen m_goaldiff = mean(goaldiff)
twoway (line m_goaldiff year, lcolor(navy)), xlabel(1908(20)2018) ///
title(Goal Differential by Year)
twoway (line m_goaldiff year, lcolor(navy)) ///
(line m_goals year, lcolor(green) lwidth(thin)) ///
(line m_conceded year, lcolor(red) lwidth(thin)), ///
xlabel(1908(30)2018) yline(0, lcolor(grey) lwidth(thin)) ///
title(Goal Differential by Year) subtitle(Overlay Chart) ///
ytitle(Year)
translate Stata_WClog.smcl Stata_WClog.pdf, rmargin(.5)
translate Stata_WClog.smcl Stata_WClog.txt , replace