{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Week 8 Lab "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Monte Carlo Simulation of a Simpel Schooling Model (continued)**\n",
"\n",
"We will continue with Card's (1993) return to schooling estimation in the week 9 lab.\n",
"\n",
"This week and next week we will run Monte Carlo Simulations: We will create the *random sample* from a data generating process of our choosing and then estimate the model many many times to study the properties of the estimator.\n",
"\n",
"For that purpose, create a sample according to the following DGP:\n",
"\n",
"$$\n",
"\\begin{align*}\n",
" u & \\sim \\mathcal{N}(0, \\sigma_u^2) \\\\\n",
" A & \\sim \\mathcal{N}(0, \\sigma_A^2) && \\text{(ability)}\\\\\n",
" S &= \\pi + A && \\text{(schooling)}\\\\\n",
" Y &= \\exp (\\beta_1 + \\beta_2 S + \\beta_3 A + u) && \\text{(earnings)}\n",
"\\end{align*}\n",
"$$\n",
"\n",
"When you take logarithm of $Y$ you obtain $\\ln Y = \\beta_1 + \\beta_2 S + \\beta_3 A + u$. Our main focus is the return to schooling $\\beta_2$.\n",
"\n",
"In this DGP, a person's ability follows a normal distribution (not realisitic), schooling is centered around a mean of $\\pi$ years and also normally distributed (totally unrealistic), and earnings are determined by a combination of schooling and ability and a random error term. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 1\n",
"\n",
"Take your function `schooling_sample` from last week, and re-order its arguments like so:\n",
"\n",
" function schooling_sample(b2, b3, n, p=13.2, b1=4.7, su=0.175, sa=7.2)\n",
"\n",
"We're doing this to prepare for a few power simulations below. We want to regard $\\beta_2, \\beta_3$ and the sample size as variable parameters, whereas $\\beta_1, \\pi$ and the variances $\\sigma_A^2, \\sigma_u^2$ are fixed.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Distributions, Random, Plots\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 2\n",
"\n",
"Write a so-called **closure**: a version of `schooling_sample` that only takes the arguments `b2, b3, n`. Call this function `schooling_sample_closure`.\n",
"\n",
"Then type `dgp_base = schooling_sample_closure(13.2, 4.7, 0.175, 7.2)`.\n",
"\n",
"What type of object is `dgp_base`?"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With your closure, you can instantiate a particular DGP like so:\n",
"\n",
" dgp_1 = dgp_base(0.07, 0, 30)\n",
"\n",
"This creates a sample of size 30 from the DGP that has $\\beta_2 = 0.07$ and $\\beta_3=0$.\n",
"\n",
"You could access the fixed parameters as object fields:\n",
"\n",
" dgp_base.su\n",
"\n",
"Try it out!"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 3\n",
"\n",
"Write a function `schooling_power` that takes as arguments:\n",
"\n",
"* the value of $\\beta_2$; \n",
"\n",
"* the value of $\\beta_3$;\n",
"\n",
"* the sample size $n$;\n",
"\n",
"* a schooling sample closure;\n",
"\n",
"* the value $\\beta_2^{null}$ of $\\beta_2$ tested under the null hypothesis;\n",
"\n",
"and that \n",
"\n",
"* creates `rep=1,000` schooling samples;\n",
"\n",
"* runs a hypothesis test $\\beta_2 = \\beta_2^{null}$ each time;\n",
"\n",
"* returns the proportion of 'rejected' test results.\n",
"\n",
"(Given the DGP above, would you use homoskedastic or heteroskedastic standard errors to construct your confidence interval?)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 4\n",
"\n",
"Fill out some powers for the following configurations: \n",
"\n",
"(Note: $\\beta_3 = 0$ always, ruling out endogeneity)\n",
"\n",
"| $\\beta_2$ | $\\beta_2^{null}$ | $n$ | Empirical power |\n",
"|-------------------|---------------------------|---------|-----------------|\n",
"| 0.07 | 0.07 | 30 | |\n",
"| 0.07 | 0.05 | 30 | |\n",
"| 0.07 | 0.09 | 30 | |\n",
"| 0.07 | 0.07 | 100 | |\n",
"| 0.07 | 0.05 | 100 | |\n",
"| 0.07 | 0.09 | 100 | |\n",
"| 0.07 | 0.07 | 1000 | |\n",
"| 0.07 | 0.05 | 1000 | |\n",
"| 0.07 | 0.09 | 1000 | |\n",
"| 0.07 | 0.07 | 10000 | |\n",
"| 0.07 | 0.05 | 10000 | |\n",
"| 0.07 | 0.09 | 10000 | |\n",
"\n",
"Notice: whenever $\\beta_2 = \\beta_2^{null}$ we're calculating the *empirical size*. Everywhere else it's the *empirical power*."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 5\n",
"\n",
"Let's be more systematic: Instead of calculating the empirical power at a few points, let's simulate the power curve.\n",
"\n",
"Write a function `schooling_power_curve` which puts `schooling_power` inside a loop which runs across a symmetric interval for $\\beta_2^{null}$ (for example, from `0.02` to `0.12`). \n",
"\n",
"The function should return a graph representing a power curve."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 6\n",
"\n",
"Plot power functions at various parameter configurations. Also vary $\\beta_3$ to see what happens under endogeneity.\n",
"\n",
"Think about $\\widehat{\\beta}_2^{OLS}$ when $\\beta_3 \\neq 0$. What is the probability limit of $\\widehat{\\beta}_2^{OLS}$? How does this manifest in the power curve?"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"metadata": {
"interpreter": {
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
},
"kernelspec": {
"display_name": "Julia 1.7.2",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}