-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorrelation Matrices for Logarithmic & Non-Logarithmic
166 lines (141 loc) · 4.03 KB
/
Correlation Matrices for Logarithmic & Non-Logarithmic
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* 1st Question */
/* Assigning a value of 1 to each individual from 1 - 15 */
egen P = anymatch(personid), values (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
/* drop everyone except the first 15 people */
keep if P
drop P
gen P = 0
/* assigning '1' to every first observation */
bysort personid (personid): replace P= 1 if _n == 1
/* dropping everything except the 1st observation */
keep if P == 1
drop P
/* Making lists for x1 and x2 */
global x1 educ potexper ability
global x2 mothered fathered siblings
global y logwage
/* Part a */
/* regressing y on x1 */
regress $y $x1
/* reference for part c to manually calculate r-squared */
ereturn list
scalar rss1 = e(rss)
scalar tss1 = e(rss) + e(mss)
scalar r2_1 = 1-(rss1/tss1)
display r2_1
/* reference for adjusted r-squared */
scalar no_obs1 = e(N)
scalar no_var1 = e(df_m)
scalar adjr2_1 = 1-(1-r2_1)*(no_obs1-1)/(no_obs1-(no_var1+1))
display adjr2_1
/* Part b */
/* regressing y on x1 and x2 */
regress $y $x1 $x2
/* reference for part c to manually calculate r-squared */
ereturn list
scalar rss3 = e(rss)
scalar tss3 = e(rss) + e(mss)
scalar r2_3 = 1-(rss3/tss3)
display r2_3
/* reference for adjusted r-squared */
scalar no_obs2 = e(N)
scalar no_var2 = e(df_m)
scalar adjr2_2 = 1-(1-r2_2)*(no_obs2-1)/(no_obs2-(no_var2+1))
display adjr2_2
/* Part c and d */
regress $y $x1, noconstant
/* reference to manually calculate r-squared */
ereturn list
scalar rss2 = e(rss)
scalar tss2 = e(rss) + e(mss)
scalar r2_2 = 1-(rss2/tss2)
display r2_2
/* reference for adjusted r-squared */
scalar no_obs2 = e(N)
scalar no_var2 = e(df_m)
scalar adjr2_2 = 1-(1-r2_2)*(no_obs2-1)/(no_obs2-(no_var2+1))
display adjr2_2
regress $y $x1 $x2, noconstant
/* reference to manually calculate r-squared */
ereturn list
scalar rss4 = e(rss)
scalar tss4 = e(rss) + e(mss)
scalar r2_4 = 1-(rss4/tss4)
display r2_4
/* reference for adjusted r-squared */
scalar no_obs2 = e(N)
scalar no_var2 = e(df_m)
scalar adjr2_2 = 1-(1-r2_2)*(no_obs2-1)/(no_obs2-(no_var2+1))
display adjr2_2
/* Part e */
/* MR5 */
/* vif */
vif
/* correlation matrices */
corr $y $x1
corr $y $x1 $x2
/* MR6 */
regress $y $x1
predict r, resid
hist r, freq normal
regress $y $x1 $x2
predict r2, resid
hist r2, freq normal
/* 2nd Question */
/* Obtaining the per capita quantity variable */
gen quantity_pc = gasexp/(gasp*pop)
/* Part a */
regress quantity_pc income puc ps ppt pnc pn pd gasp year
/* Part b */
/* Hypothesis Test */
regress gasexp pnc puc
/* Testing if pnc = puc */
test pnc = puc
/* Part c */
/* Determining elasticity values */
/* own price elasticity of demand */
margins if year==2004, eyex(gasp)
/* income elasticity */
margins if year==2004, eyex(income)
/* cross-price elasticity with respect to changes in the price of public transportation */
margins if year==2004, eyex(ppt)
/* Part d */
/* Generating the logarithmic regressions */
gen lngy = log(quantity_pc)
gen lnincome = log(income)
gen lngasp = log(gasp)
gen lnpnc = log(pnc)
gen lnpuc = log(puc)
gen lnppt = log(ppt)
gen lnpd = log(pd)
gen lnpn = log(pn)
gen lnps = log(ps)
/* regressing them */
reg lngy lnincome lngasp lnpnc lnpuc lnppt lnpd lnpn lnps year
/* checking for elasticity using margins */
margins, dydx(lngasp lnppt lnincome) at(year = 2004)
/* Part e */
/* Correlation matrices for both logarithmic and non-logarithmic */
correlate income gasp pnc puc ppt pd pn ps year
correlate lnincome lngasp lnpnc lnpuc lnppt lnpd lnpn lnps year
/* Part f */
/* Normalizing for 2004 */
gen nmgasp = gasp * 100/gasp[52]
gen nmpnc = pnc * 100/pnc[52]
gen nmpuc = puc * 100/puc[52]
gen nmppt = ppt * 100/ppt[52]
gen nmpd = pd * 100/pd[52]
gen nmpn = pn * 100/pn[52]
gen nmps = ps * 100/ps[52]
regress quantity_pc nmgasp nmpnc nmpuc nmppt nmpd nmpn nmps income year
/* Repeating the above for logarithms */
gen lnnmgasp = ln(nmgasp)
gen lnnmpnc = ln(nmpnc)
gen lnnmpuc = ln(nmpuc)
gen lnnmppt = ln(nmppt)
gen lnnmpd = ln(nmpd)
gen lnnmpn = ln(nmpn)
gen lnnmps = ln(nmps)
gen lnincome = ln(income)
gen lnquantity_pc = ln(quantity_pc)
regress lnquantity_pc lnnmgasp lnnmpnc lnnmpuc lnnmppt lnnmpd lnnmpn lnnmps lnincome year