Skip to content

Instantly share code, notes, and snippets.

@bbdaniels
Created November 5, 2018 19:46
Show Gist options
  • Save bbdaniels/0222185fe0a1d084e627ab79aaf1065a to your computer and use it in GitHub Desktop.
Save bbdaniels/0222185fe0a1d084e627ab79aaf1065a to your computer and use it in GitHub Desktop.
[ritest] with [ivregress]
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"clear"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of observations (_N) was 0, now 1,000\n"
]
}
],
"source": [
"set obs 1000"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"gen instrument= rnormal() > 0"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"gen x = instrument + rnormal()*.25"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"gen y = x + rnormal()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"First-stage regressions\n",
"-----------------------\n",
"\n",
" Number of obs = 1,000\n",
" F( 1, 998) = 4172.15\n",
" Prob > F = 0.0000\n",
" R-squared = 0.8070\n",
" Adj R-squared = 0.8068\n",
" Root MSE = 0.2404\n",
"\n",
"------------------------------------------------------------------------------\n",
" x | Coef. Std. Err. t P>|t| [95% Conf. Interval]\n",
"-------------+----------------------------------------------------------------\n",
" instrument | .9832522 .0152225 64.59 0.000 .9533805 1.013124\n",
" _cons | .013795 .0105134 1.31 0.190 -.006836 .0344259\n",
"------------------------------------------------------------------------------\n",
"\n",
"\n",
"Instrumental variables (2SLS) regression Number of obs = 1,000\n",
" Wald chi2(1) = 276.76\n",
" Prob > chi2 = 0.0000\n",
" R-squared = 0.2506\n",
" Root MSE = 1.0148\n",
"\n",
"------------------------------------------------------------------------------\n",
" y | Coef. Std. Err. z P>|z| [95% Conf. Interval]\n",
"-------------+----------------------------------------------------------------\n",
" x | 1.087043 .065342 16.64 0.000 .958975 1.215111\n",
" _cons | -.0475267 .045 -1.06 0.291 -.1357252 .0406717\n",
"------------------------------------------------------------------------------\n",
"Instrumented: x\n",
"Instruments: instrument\n"
]
}
],
"source": [
"ivregress 2sls y (x=instrument) , first"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(running ivregress on estimation sample)\n",
". ivregress 2sls y (x=instrument)\n",
"\n",
"Instrumental variables (2SLS) regression Number of obs = 1,000\n",
" Wald chi2(1) = 276.76\n",
" Prob > chi2 = 0.0000\n",
" R-squared = 0.2506\n",
" Root MSE = 1.0148\n",
"\n",
"------------------------------------------------------------------------------\n",
" y | Coef. Std. Err. z P>|z| [95% Conf. Interval]\n",
"-------------+----------------------------------------------------------------\n",
" x | 1.087043 .065342 16.64 0.000 .958975 1.215111\n",
" _cons | -.0475267 .045 -1.06 0.291 -.1357252 .0406717\n",
"------------------------------------------------------------------------------\n",
"Instrumented: x\n",
"Instruments: instrument\n",
"\n",
"Resampling replications (100)\n",
"----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 \n",
".................................................. 50\n",
".................................................. 100\n",
"\n",
" command: ivregress 2sls y (x=instrument)\n",
" _pm_1: _b[x]\n",
" res. var(s): instrument\n",
" Resampling: Permuting instrument\n",
"Clust. var(s): __000001\n",
" Clusters: 1000\n",
"Strata var(s): __000000\n",
" Strata: 1\n",
"\n",
"------------------------------------------------------------------------------\n",
"T | T(obs) c n p=c/n SE(p) [95% Conf. Interval]\n",
"-------------+----------------------------------------------------------------\n",
" _pm_1 | 1.087043 71 100 0.7100 0.0454 .610734 .7964258\n",
"------------------------------------------------------------------------------\n",
"Note: Confidence interval is with respect to p=c/n.\n",
"Note: c = #{|T| >= |T(obs)|}\n"
]
}
],
"source": [
"ritest instrument _b[x] , reps(100) : ivregress 2sls y (x=instrument)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Stata",
"language": "stata",
"name": "stata"
},
"language_info": {
"file_extension": ".do",
"mimetype": "text/x-stata",
"name": "stata"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment