Vous êtes sur la page 1sur 62

IRCO 454

Professor Edmund Malesky,


UCSD
1
Copyrighted by Edmund Malesky. Do not distribute without permission.
Outline of Todays Lecture
1) Introduction to QM2
2) Flip to the last page of the novel
What is linear modeling and how is it
used?
3) A brief review of critical concepts that
you learned in QM1.


2
Copyrighted by Edmund Malesky. Do not distribute without permission.
Goals of the Course
Learn to do quantitative empirical work for
use in economic analysis, public policy
and social sciences.
Learn the basic properties of the
regression estimator.
Learn to diagnose and address problems
with fit between data and estimator
Learn to present results in a meaningful
way.
Learn STATA.
3
Copyrighted by Edmund Malesky. Do not distribute without permission.
Topics We Will Address
ONE basic equation:
Y =
0
+
1
X + u
This is a VERY flexible model for
understanding social, political, economic
behavior.
First part of course will be about HOW to
estimate
0
and
1

Also about what ASSUMPTIONS are
needed to make those estimates.
4
Copyrighted by Edmund Malesky. Do not distribute without permission.
Topics We Will Address
Y =
0
+
1
X + u
The rest of the course will be about what
to do if those assumptions are not
reasonable
How do we make sure that our estimates
of
1
are unbiased, or at least consistent
5
Copyrighted by Edmund Malesky. Do not distribute without permission.
Problems with u
(the error term /residual)
Omitted Variable Bias
Heteroskedasticity
Dichotomous Dependent Variables
Autocorrelation

6
Copyrighted by Edmund Malesky. Do not distribute without permission.
Problems with X
Measurement Error
Multicollinearity
7
Copyrighted by Edmund Malesky. Do not distribute without permission.
Problems with
0
&
1

Dummy variables for new intercepts
Non-linear effects
Interaction Effects
8
Copyrighted by Edmund Malesky. Do not distribute without permission.
Problems with Y
Endogeneity Bias
Selection Bias
The use (abuse) of R-squared and curve
fitting
9
Copyrighted by Edmund Malesky. Do not distribute without permission.
Course Structure
(Two Components)
Monday: A theory based lecture on the
mathematical properties of the linear
regression technique and problems with its
application. No laptops!

Wednesdays: A practical hands-on lab,
where we will learn how to program
statistical code in STATA. Bring your
laptops!!
10
Copyrighted by Edmund Malesky. Do not distribute without permission.
Course Requirements
50% - Weekly Problem Sets
Will your own computer code (A.K.A. The .Do File)
File sent in one hour before class on the
Wednesday following distribution.
Send to QM2 Homework Folder
LastName_ProblemSet#
Whether .do file runs is worth 20% of HW grade
Word write-up handed in before class lecture.

50% - Final Take-Home Exam
Will test cumulative knowledge.
Will involve a .do file
Grade will be determined based on your answers to
the questions and whether I can successfully run your
.do files without error.
11
Copyrighted by Edmund Malesky. Do not distribute without permission.
Required Readings
Wooldridge, Jeffrey M. 2008. Introductory
Economics: A Modern Approach, Volume
4E.
Other brief reading assignments sent out
by professor.
12
Copyrighted by Edmund Malesky. Do not distribute without permission.
One Administrative Issue
What do we do to make-up for missing
classes due to Martin Luther King and
Presidents Day?
Continue with class as normal?
Schedule make-up class?
Webcast missing class?
Malesky lectures at TA review sessions?

13
Copyrighted by Edmund Malesky. Do not distribute without permission.
Optional Readings
Baum, Christopher. 2008. An Introduction to Modern
Econometrics Using Stata. Stata Press.
http://www.stata.com/bookstore/statabooks.html
Xiao Chen, Philip B. Ender, Michael Mitchell & Christine
Wells. 2006. Stata Web Books: Regression with Stata.
http://www.ats.ucla.edu/stat/stata/webbooks/reg/default.htm
Zorn, Christopher. Stata for Dummies
http://www.buec.udel.edu/yatawarr/Stata4Dummies.pdf
Acock, Alan. 2005. A Gentle Introduction to Stata.
http://www.stata.com/bookstore/statabooks.html
14
Copyrighted by Edmund Malesky. Do not distribute without permission.
A New Way of Studying
Excelling in QM2 requires a different
approach to learning than in many other
classes at IRPS.
This course is about skill acquisition. The
speed-reading, participation, and writing
skills that you have fine-tuned in other
courses are important, but they will serve
you less well here.
At the end of the day, you will be evaluated
on your ability to understand and employ
OLS regression in policy analysis. Period.

15
Copyrighted by Edmund Malesky. Do not distribute without permission.
READING
Reading assignments are short, but they are
difficult, technical, and essential to understanding
the material in the course.
You cannot read Wooldridge like you are reading
for the policy or political science courses at IRPS.
Find a quiet spot, read with a pencil in hand,
highlight and take notes vigorously.
Do not skip over the equations or boxes.
Read the equations, as if you are reading a sentence.
The boxes are examples of the material covered. Refer
back to the preceding lesson, as you read each box.

16
Copyrighted by Edmund Malesky. Do not distribute without permission.
Lectures
I will provide you with my lecture notes at the
end of every class.
Do not feel obligated to type everything I say.
You will do much better if you simply listen,
ask questions, and record a few important
issues.
Stop me if you dont understand.
Probably half or more of the class is also
confused.
If you didnt understand slide 10, you will not
understand slide 11, and ZZZZZZZZZZZZZ

17
Copyrighted by Edmund Malesky. Do not distribute without permission.
STATA
Learning to write a .do file is like learning to
speak another language. All of you have
mastered this ability before.
Keep your own glossary of commands and
syntax that I introduce to you in the course.
The process will help you remember the code
and give you a personalized reference guide.
Feel free to make use of the help function, pull-
down menus, and the UCLA statistics website.
When using help, look most carefully at
examples.
18
Copyrighted by Edmund Malesky. Do not distribute without permission.
Homework
Feel free to work in groups, but make sure
you write-up your own final .do file. Do not
cut and paste the work of others. After the
group session, do the write-up and .do file
on your own. That will help you know if
you really understand it.


19
Copyrighted by Edmund Malesky. Do not distribute without permission.
Prof. and TA Availability
Prof Malesky
Office Hours: MW 3 to 4 and by
appointment.

Kevin
OH/Breakout: Thursday, 3:30 pm

Matt
OH/Breakout:
20
Copyrighted by Edmund Malesky. Do not distribute without permission.
Any Questions?
21
Copyrighted by Edmund Malesky. Do not distribute without permission.



The Linear Regression Model
Approach to Research


Otherwise known as

Advanced Line Drawing
22
Copyrighted by Edmund Malesky. Do not distribute without permission.
The General Linear Model refers to a
class of statistical models which are
generalizations of simple linear
regression analysis.
Regression is the predominant statistical
tool used in the social sciences due to its
simplicity and versatility.
Also called Linear Regression Analysis.
General Linear Model
23
Copyrighted by Edmund Malesky. Do not distribute without permission.
Notations for Regression
Line
Alternate Mathematical Notation for
the straight line
th Grade Geometry

Statistics Literature

Econometrics Literature



y mx b = +
Y a bX e
i i i
= + +
Y =
0
+
1
X + u
Wooldrigde
uses this
specification,
so we will
too!
24
Copyrighted by Edmund Malesky. Do not distribute without permission.
Translating Math into English
The linear model states that the
dependent variable is directly proportional
to the value of the independent variable.
Thus, if a theory implies that Y increases
in direct proportion to an increase in X, it
implies a specific mathematical model of
behavior - the linear model.
E.g. Its the economy, stupid!

25
Copyrighted by Edmund Malesky. Do not distribute without permission.
Simple Linear Regression:
The Basic Mathematical Model
Regression is based on the concept
of the simple proportional relationship
A.K.A . . . the straight line.
We can express this idea
mathematically!
Y =
0
+
1
X + u

26
Copyrighted by Edmund Malesky. Do not distribute without permission.
The Theory Implies the Math
ALL statements of relationships between
variables imply a mathematical structure.
Even if we dont like to phrase our theories
in these terms, they DO imply
mathematical relationships.
Much of this course is about elaborating
the basic model to fit our more nuanced
theories.
27
Copyrighted by Edmund Malesky. Do not distribute without permission.
Implications of a Linear Model
The linear aspect means that the same
increase in inflation will always produce
the same reduction in presidential
approval.
This is perhaps the most restrictive of all
the assumptions of OLS.
We will work to loosen this assumption
through the quarter.
28
Copyrighted by Edmund Malesky. Do not distribute without permission.
The Regression Parameters

0
= the intercept
the point where the line crosses the Y-axis.
(the value of the dependent variable when all of
the independent variables = 0)

1
= the slope
the increase in the dependent variable per unit
change in the independent variable (also known
as the 'rise over the run')
29
Copyrighted by Edmund Malesky. Do not distribute without permission.
Regression in a Perfect World
Y = 1X
0
2
4
6
8
10
12
1 2 3 4 5 6 7 8 9 10
Y
X
The Straight Line
30
Copyrighted by Edmund Malesky. Do not distribute without permission.
but life is full of errors
Y = 1X + u
0
2
4
6
8
10
12
0 1 2 3 4 5 6 7 8 9 10 11
Y
X
Simple Linear Regression
31
Copyrighted by Edmund Malesky. Do not distribute without permission.
The Error Term
Our models do not predict behavior
perfectly.
Life is not a Just So Story.
So we add a term to adjust or compensate
for the errors in prediction (u).
Much of our ability to estimate
1
depends
upon the assumptions we make about the
errors (u).
Sometimes u is called the Disturbance
32
Copyrighted by Edmund Malesky. Do not distribute without permission.
The 'Goal' of Ordinary Least
Squares
Ordinary Least Squares (OLS) is a method
of finding the linear model which
minimizes the sum of the squared errors.
Such a model provides the best
explanation/prediction of the data.
It is the Best Linear Unbiased Estimator
Its BLUE
33
Copyrighted by Edmund Malesky. Do not distribute without permission.
Other Goals are Possible
Minimize total errors
Minimize Absolute Value of Errors
Maximum Likelihood Models
OLS is a special case of MLE
34
Copyrighted by Edmund Malesky. Do not distribute without permission.
Why Least Squared error?
Why not simply minimum error?
The errors about the line sum to 0.0!
Minimum absolute deviation (error) models
now exist, but they are mathematically
cumbersome.
Try algebra with | Absolute Value | signs!
35
Copyrighted by Edmund Malesky. Do not distribute without permission.
Implications of Squared Errors
This model seeks to avoid BIG misses
A big u for one case leads to a REALLY
big u
2
.
This means regression results can be
heavily influenced by outlier cases
Some feel this is theoretically appropriate
Always look at your data
36
Copyrighted by Edmund Malesky. Do not distribute without permission.
Minimizing the Sum of Squared
Errors
How to put the Least in OLS?
In mathematical jargon we seek to
minimize the residual sum of squares
(SSR), where:

( )

=
=
n
i
i i
y y SSR
1
2

=
=
n
i
i
u
1
2

37
Copyrighted by Edmund Malesky. Do not distribute without permission.
Picking the Parameters
To Minimize SSR, we need parameter
estimates.
In calculus, if you wish to know when
a function is at its minimum, you take
the first derivative.
In this case we must take partial
derivatives since we have two
parameters (
0
&
1
) to worry about.
38
Copyrighted by Edmund Malesky. Do not distribute without permission.
How good does it fit?
To measure reduction in errors we need
a benchmark variable is a relevant and
tractable benchmark for comparing
predictions for comparison.
The mean of the dependent.
The mean of Y represents our best
guess at the value of Y
i
absent other
information.
39
Copyrighted by Edmund Malesky. Do not distribute without permission.
Sums of Squares
This gives us the following 'sum-of-
squares' measures:
SST=Total Sum of Squares
SSE= Explained Sum of Squares
SSR= Residual (Unexplained Sum of Squares)
Total Variation (SST) = Explained Variation (SSE) +
Unexplained Variation (SSR)
( )
2
1

=
=
n
i
i
y y SST
( )

=
=
n
i
i
y y SSE
1
2

( )

=
=
n
i
i i
y y SSR
1
2

40
Copyrighted by Edmund Malesky. Do not distribute without permission.
Explained and Unexplained
Variation


Y


X

X
i
y
i
0

B
1

B
x y
1 0

B + B =
i
y

i
u

( ) y y
i

41
Copyrighted by Edmund Malesky. Do not distribute without permission.
Explained and Unexplained
Variation
Y

X
i
y
i
i
y

i
u

( ) y y
i

Square this quantity
and sum across all
observations and
we have our SST
(Total Sum of
Squares)
Square this
quantity and sum
across all
observations and
we have our
SSE (Explained
Sum of Squares)
X
Square this
quantity and sum
across all
observations and
we have our SSR
(Residual Sum of
Squares)
42
Copyrighted by Edmund Malesky. Do not distribute without permission.
Some Confusing Terminology
Occasionally you may see people refer
instead to USS (Unexplained) and ESS
(Error)
These terms are interchangeable, but
ESS can be confused with explained sum
of squares
USS is not confused with any
mathematical jargon, but does pose issues
for statistical work on the US Navy.
43
Copyrighted by Edmund Malesky. Do not distribute without permission.
Lets Test Some Theories
Presidential approval depends upon the
performance of the US economy
The development of US military power
was a response to Americas threatening
environment

44
Copyrighted by Edmund Malesky. Do not distribute without permission.
Plotting Approval and Inflation
45
Copyrighted by Edmund Malesky. Do not distribute without permission.
Regressing Approval on
Inflation
. reg approve inflat

Source | SS df MS Number of obs = 46
---------+------------------------------ F( 1, 44) = 17.20
Model | 1960.60398 1 1960.60398 Prob > F = 0.0002
Residual | 5015.26094 44 113.983203 R-squared = 0.2811
---------+------------------------------ Adj R-squared = 0.2647
Total | 6975.86492 45 155.01922 Root MSE = 10.676

------------------------------------------------------------------------------
approve | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
inflat | -2.213684 .5337539 -4.147 0.000 -3.289394 -1.137973
_cons | 63.80565 2.711964 23.527 0.000 58.34004 69.27125
------------------------------------------------------------------------------


46
Copyrighted by Edmund Malesky. Do not distribute without permission.
Fitting Inflation to Approval
(mean) inflat
(mean) approve Fitted values
-.263876 12.8595
28.3333
76.2143
47
Copyrighted by Edmund Malesky. Do not distribute without permission.
Plotting US Power & Disputes
u
s
c
a
p
b
l
numtargt
0 7
.03
.38
48
Copyrighted by Edmund Malesky. Do not distribute without permission.
Regress US Power on Disputes
. reg uscapbl numtargt

Source | SS df MS Number of obs = 177
---------+------------------------------ F( 1, 175) = 18.61
Model | .110444241 1 .110444241 Prob > F = 0.0000
Residual | 1.03834672 175 .00593341 R-squared = 0.0961
---------+------------------------------ Adj R-squared = 0.0910
Total | 1.14879096 176 .006527221 Root MSE = .07703

------------------------------------------------------------------------------
uscapbl | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
numtargt | .0201142 .0046621 4.314 0.000 .010913 .0293155
_cons | .1455665 .0067132 21.684 0.000 .1323172 .1588157
------------------------------------------------------------------------------

49
Copyrighted by Edmund Malesky. Do not distribute without permission.
Fitting Disputes to US Power
numtargt
uscapbl Fitted values
0 7
.03
.38
50
Copyrighted by Edmund Malesky. Do not distribute without permission.
A Brief Review of Critical Concepts
Measures of Central Tendency
(Mean, Median, Mode)


Population Variance



Standard Deviation

Covariance

Correlation

Marginal Effect


1
(1/ )
n
i
i
x n x
=
=

2
2 2
1
( ) [( ( )) ]
(1/ ) ( )
n
i
i
Var X E X E X
n x x o
=

= =

2
( ) sd X o =
1
y x | A = A
| |
( , ) ( ( ))( ( )) Cov X Y E X E X Y E Y
( , )
( , )
( ) * ( )
XY
X Y
Cov X Y
Corr X Y
sd X sd Y
o
o o
=
51
Copyrighted by Edmund Malesky. Do not distribute without permission.
Distributions The Usual Suspects
Normal Distribution
Standard Normal
Chi-Square
t
F

52
Copyrighted by Edmund Malesky. Do not distribute without permission.
The Normal Distribution
(Probability Density Function)
x
2 2
2
1
( ) [ ( ) / 2 ]
2
( , )
f x E x u
X Normal u
o
o t
o
=
~

53
Copyrighted by Edmund Malesky. Do not distribute without permission.
The Standard Normal
Distribution (PDF)
Z
0
2
1
( ) [ / 2]
2
(0,1)
z E z
Z Normal
|
t
=
~
54
Copyrighted by Edmund Malesky. Do not distribute without permission.
Chi-Square Distribution
i
n
2
i=1
Let Z , 1, 2..., be independent random variables, each distributed
standard normal.
= Z
( , 2 )
i
i n
n n
_
_
=
~

f(x)
x
df=2
df=4
df=6
55
Copyrighted by Edmund Malesky. Do not distribute without permission.

t-distribution:
The Statistical Workhorse
0
3 -3
Let have a chi-square distribution
with degrees of freedom.
Z
T=
/
(0, /( 2))
n
n
t n n
_
_
~
df=2
df=4
df=6

As the degrees of
freedom increase, the
t-distribution
approaches the normal
distribution.
56
Copyrighted by Edmund Malesky. Do not distribute without permission.
Quick Review:
Hypothesis Testing

In STATA, the null hypothesis for a two-
tailed t-test is:

H
0:

j
=0




57
Copyrighted by Edmund Malesky. Do not distribute without permission.
Quick Review:
Hypothesis Testing

To test the hypothesis, I need to have a rejection rule. That
is, I will reject the null hypothesis if, t is greater than some
critical value (c).





c is up to me to some extent, I must determine what level of
significance I am willing to accept. For instance, if my t-
value is 1.85 with 40 df and I was willing to reject only at the
5% level, my c would equal 2.021 and I would not reject the
null. On the other hand, if I was willing to reject at the 10%
level, my c would be 1.684, and I would reject the null
hypotheses.

| | t c > =
58
Copyrighted by Edmund Malesky. Do not distribute without permission.


t-distribution:
5 % rejection rule for the that H
0:

j
=0
with 25 degrees of freedom
Rejection Region
Area=.025
Rejection Region
Area=.025

0
Looking at table G-
2, I find the critical
value for a two-
tailed test is 2.06
2.06 -2.06
59
Copyrighted by Edmund Malesky. Do not distribute without permission.
Quick Review:

But this operation hides some very useful
information.
STATA has decided that it is more useful to
provide what is the smallest level of significance
at which the null hypothesis would be rejected.
This is known as the p-value.
In the previous example, we know that
.05<p<.10.
To calculate the p, STATA computes the area
under the probability density function.
60
Copyrighted by Edmund Malesky. Do not distribute without permission.
T-distribution:
Obtaining the p-value against a two-sided
alternative, when t=1.85 and df=40.
P-value=P(|T|>t)
In this case,
P(|T|>1.85)=
2P(T>1.85)=2(.0359)
=.0718
Area=.9282
Rejection Region
Area=.0359
Rejection Region
Area=.0359

0
61
Copyrighted by Edmund Malesky. Do not distribute without permission.
F Distribution
f(x)
x
df=2,8
df=6,8
df=6,20
1
2
1
2
2/
2/
k
k
k
F
k
_
_
=
F and Chi Square
testing involves
only a one-tailed
test of the area
underneath the
right portion of the
curve.
62
Copyrighted by Edmund Malesky. Do not distribute without permission.

Vous aimerez peut-être aussi