Skip to content

Commit

Permalink
#30 Last Update
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraMartinezGutierrez committed Mar 8, 2022
1 parent c461051 commit b7a246b
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
{
"cell_type": "code",
"execution_count": 14,
"id": "339de597",
"id": "9dd1e0db",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1001,7 +1001,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 77,
"id": "48763755",
"metadata": {},
"outputs": [
Expand All @@ -1016,26 +1016,26 @@
"────────────────────────────────────────────────────────────────────────────────\n",
" Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95%\n",
"────────────────────────────────────────────────────────────────────────────────\n",
"(Intercept) 1.23713e-17 0.0041763 0.00 1.0000 -0.00829952 0.00829952\n",
"r_D -0.0502399 0.0151951 -3.31 0.0014 -0.080437 -0.0200428\n",
"(Intercept) -5.44341e-18 0.00417979 -0.00 1.0000 -0.00830646 0.00830646\n",
"r_D -0.0500007 0.0152165 -3.29 0.0015 -0.0802403 -0.0197611\n",
"────────────────────────────────────────────────────────────────────────────────"
]
},
"execution_count": 21,
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Seat values for Lasso\n",
"\n",
"lasso_model = fit(LassoModel, term(:Y) ~ sum(term.(names(data[!, Not([\"Y\", \"D\"])]))), data; α = 0.9999)\n",
"lasso_model = fit(LassoModel, term(:Y) ~ sum(term.(names(data[!, Not([\"Y\", \"D\"])]))), data; α = 0.8)\n",
"r_Y = residuals(lasso_model)\n",
"r_Y = DataFrame([r_Y], [:r_Y])\n",
"\n",
"# Part. out d\n",
"\n",
"lasso_model = fit(LassoModel, term(:D) ~ sum(term.(names(data[!, Not([\"Y\", \"D\"])]))), data; α = 0.9999)\n",
"lasso_model = fit(LassoModel, term(:D) ~ sum(term.(names(data[!, Not([\"Y\", \"D\"])]))), data; α = 0.8)\n",
"r_D = residuals(lasso_model)\n",
"r_D = DataFrame([r_D], [:r_D])\n",
"\n",
Expand All @@ -1047,17 +1047,17 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 78,
"id": "47debbc4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.02004279098812973"
"-0.01976108418900473"
]
},
"execution_count": 22,
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1076,15 +1076,15 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 79,
"id": "c4e19d41",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Coefficient for D via partialling-out using lasso is: -0.05023991997750313\n"
"Coefficient for D via partialling-out using lasso is: -0.05000069917512743\n"
]
}
],
Expand Down Expand Up @@ -1114,46 +1114,46 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 87,
"id": "cd77ef49",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1×4 Named Matrix{Float64}\n",
"A ╲ B │ 1 2 3 4\n",
"──────┼───────────────────\n",
"LASSO │ 0.0 0.0 0.0 0.0"
" A ╲ B │ 1 2 3 4\n",
"─────────────┼───────────────────\n",
"DOUBLE LASSO │ 0.0 0.0 0.0 0.0"
]
},
"execution_count": 24,
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_2 = NamedArray(zeros(1, 4))\n",
"setnames!(table_2, [\"LASSO\"], 1)\n",
"setnames!(table_2, [\"DOUBLE LASSO\"], 1)\n",
"table_2"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 88,
"id": "17fbb3c1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1×4 Named Matrix{Float64}\n",
"A ╲ B │ 1 2 3 4\n",
"──────┼───────────────────────────────────────────────\n",
"LASSO │ -0.0502399 0.0151951 -0.080437 -0.0200428"
" A ╲ B │ 1 2 3 4\n",
"─────────────┼───────────────────────────────────────────────\n",
"DOUBLE LASSO │ -0.0500007 0.0152165 -0.0802403 -0.0197611"
]
},
"execution_count": 25,
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1169,47 +1169,47 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 89,
"id": "0aad650b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"data-frame\"><p>1 rows × 5 columns</p><table class=\"data-frame\"><thead><tr><th></th><th>model</th><th>Estimator</th><th>Std. Error</th><th>lower bound CI</th><th>upper bound CI</th></tr><tr><th></th><th title=\"String\">String</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th></tr></thead><tbody><tr><th>1</th><td>LASSO</td><td>-0.0502399</td><td>0.0151951</td><td>-0.080437</td><td>-0.0200428</td></tr></tbody></table></div>"
"<div class=\"data-frame\"><p>1 rows × 5 columns</p><table class=\"data-frame\"><thead><tr><th></th><th>model</th><th>Estimator</th><th>Std. Error</th><th>lower bound CI</th><th>upper bound CI</th></tr><tr><th></th><th title=\"String\">String</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th></tr></thead><tbody><tr><th>1</th><td>DOUBLE LASSO</td><td>-0.0500007</td><td>0.0152165</td><td>-0.0802403</td><td>-0.0197611</td></tr></tbody></table></div>"
],
"text/latex": [
"\\begin{tabular}{r|ccccc}\n",
"\t& model & Estimator & Std. Error & lower bound CI & upper bound CI\\\\\n",
"\t\\hline\n",
"\t& String & Float64 & Float64 & Float64 & Float64\\\\\n",
"\t\\hline\n",
"\t1 & LASSO & -0.0502399 & 0.0151951 & -0.080437 & -0.0200428 \\\\\n",
"\t1 & DOUBLE LASSO & -0.0500007 & 0.0152165 & -0.0802403 & -0.0197611 \\\\\n",
"\\end{tabular}\n"
],
"text/plain": [
"\u001b[1m1×5 DataFrame\u001b[0m\n",
"\u001b[1m Row \u001b[0m│\u001b[1m model \u001b[0m\u001b[1m Estimator \u001b[0m\u001b[1m Std. Error \u001b[0m\u001b[1m lower bound CI \u001b[0m\u001b[1m upper bound CI \u001b[0m\n",
"\u001b[1m \u001b[0m│\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼────────────────────────────────────────────────────────────────\n",
" 1 │ LASSO -0.0502399 0.0151951 -0.080437 -0.0200428"
"\u001b[1m Row \u001b[0m│\u001b[1m model \u001b[0m\u001b[1m Estimator \u001b[0m\u001b[1m Std. Error \u001b[0m\u001b[1m lower bound CI \u001b[0m\u001b[1m upper bound CI \u001b[0m\n",
"\u001b[1m \u001b[0m│\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼──────────────────────────────────────────────────────────────────────\n",
" 1 │ DOUBLE LASSO -0.0500007 0.0152165 -0.0802403 -0.0197611"
]
},
"execution_count": 26,
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_2_pandas = DataFrame( table_2, [ :\"Estimator\", :\"Std. Error\", :\"lower bound CI\", :\"upper bound CI\"])\n",
"model_2 = DataFrame(model = [\"LASSO\"])\n",
"model_2 = DataFrame(model = [\"DOUBLE LASSO\"])\n",
"table_2_pandas = hcat(model_2,table_2_pandas)\n",
"table_2_pandas"
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 90,
"id": "c1caa31d",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1271,11 +1271,11 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td style = \"text-align: center;\">LASSO</td>\n",
" <td style = \"text-align: center;\">-0.05024</td>\n",
" <td style = \"text-align: center;\">0.015195</td>\n",
" <td style = \"text-align: center;\">-0.080437</td>\n",
" <td style = \"text-align: center;\">-0.020043</td>\n",
" <td style = \"text-align: center;\">DOUBLE LASSO</td>\n",
" <td style = \"text-align: center;\">-0.050001</td>\n",
" <td style = \"text-align: center;\">0.015217</td>\n",
" <td style = \"text-align: center;\">-0.08024</td>\n",
" <td style = \"text-align: center;\">-0.019761</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
Expand All @@ -1294,41 +1294,41 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 91,
"id": "56ba8e89",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×4 Named Matrix{Float64}\n",
"vcat ╲ B │ 1 2 3 4\n",
"─────────┼───────────────────────────────────────────────────\n",
"OLS │ -0.00937799 0.0298877 -0.0706002 0.0518442\n",
"LASSO │ -0.0502399 0.0151951 -0.080437 -0.0200428"
" vcat ╲ B │ 1 2 3 4\n",
"─────────────┼───────────────────────────────────────────────────\n",
"OLS │ -0.00937799 0.0298877 -0.0706002 0.0518442\n",
"DOUBLE LASSO │ -0.0500007 0.0152165 -0.0802403 -0.0197611"
]
},
"execution_count": 35,
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_3 = vcat(table_1, table_2)\n",
"setnames!(table_3, [\"OLS\", \"LASSO\"], 1)\n",
"setnames!(table_3, [\"OLS\", \"DOUBLE LASSO\"], 1)\n",
"table_3"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "981f7a24",
"execution_count": 92,
"id": "84462180",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"data-frame\"><p>2 rows × 5 columns</p><table class=\"data-frame\"><thead><tr><th></th><th>model</th><th>Estimator</th><th>Std. Error</th><th>lower bound CI</th><th>upper bound CI</th></tr><tr><th></th><th title=\"String\">String</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th></tr></thead><tbody><tr><th>1</th><td>OLS</td><td>-0.00937799</td><td>0.0298877</td><td>-0.0706002</td><td>0.0518442</td></tr><tr><th>2</th><td>LASSO</td><td>-0.0502399</td><td>0.0151951</td><td>-0.080437</td><td>-0.0200428</td></tr></tbody></table></div>"
"<div class=\"data-frame\"><p>2 rows × 5 columns</p><table class=\"data-frame\"><thead><tr><th></th><th>model</th><th>Estimator</th><th>Std. Error</th><th>lower bound CI</th><th>upper bound CI</th></tr><tr><th></th><th title=\"String\">String</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th><th title=\"Float64\">Float64</th></tr></thead><tbody><tr><th>1</th><td>OLS</td><td>-0.00937799</td><td>0.0298877</td><td>-0.0706002</td><td>0.0518442</td></tr><tr><th>2</th><td>DOUBLE LASSO</td><td>-0.0500007</td><td>0.0152165</td><td>-0.0802403</td><td>-0.0197611</td></tr></tbody></table></div>"
],
"text/latex": [
"\\begin{tabular}{r|ccccc}\n",
Expand All @@ -1337,34 +1337,34 @@
"\t& String & Float64 & Float64 & Float64 & Float64\\\\\n",
"\t\\hline\n",
"\t1 & OLS & -0.00937799 & 0.0298877 & -0.0706002 & 0.0518442 \\\\\n",
"\t2 & LASSO & -0.0502399 & 0.0151951 & -0.080437 & -0.0200428 \\\\\n",
"\t2 & DOUBLE LASSO & -0.0500007 & 0.0152165 & -0.0802403 & -0.0197611 \\\\\n",
"\\end{tabular}\n"
],
"text/plain": [
"\u001b[1m2×5 DataFrame\u001b[0m\n",
"\u001b[1m Row \u001b[0m│\u001b[1m model \u001b[0m\u001b[1m Estimator \u001b[0m\u001b[1m Std. Error \u001b[0m\u001b[1m lower bound CI \u001b[0m\u001b[1m upper bound CI \u001b[0m\n",
"\u001b[1m \u001b[0m│\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼─────────────────────────────────────────────────────────────────\n",
" 1 │ OLS -0.00937799 0.0298877 -0.0706002 0.0518442\n",
" 2 │ LASSO -0.0502399 0.0151951 -0.080437 -0.0200428"
"\u001b[1m Row \u001b[0m│\u001b[1m model \u001b[0m\u001b[1m Estimator \u001b[0m\u001b[1m Std. Error \u001b[0m\u001b[1m lower bound CI \u001b[0m\u001b[1m upper bound CI \u001b[0m\n",
"\u001b[1m \u001b[0m│\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼───────────────────────────────────────────────────────────────────────\n",
" 1 │ OLS -0.00937799 0.0298877 -0.0706002 0.0518442\n",
" 2 │ DOUBLE LASSO -0.0500007 0.0152165 -0.0802403 -0.0197611"
]
},
"execution_count": 36,
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_3_pandas = DataFrame( table_3, [ :\"Estimator\", :\"Std. Error\", :\"lower bound CI\", :\"upper bound CI\"])\n",
"model_3 = DataFrame(model = [\"OLS\", \"LASSO\"])\n",
"model_3 = DataFrame(model = [\"OLS\", \"DOUBLE LASSO\"])\n",
"table_3_pandas = hcat(model_3, table_3_pandas)\n",
"table_3_pandas"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "e6b8b04d",
"execution_count": 93,
"id": "33d2533b",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1432,11 +1432,11 @@
" <td style = \"text-align: center;\">0.051844</td>\n",
" </tr>\n",
" <tr>\n",
" <td style = \"text-align: center;\">LASSO</td>\n",
" <td style = \"text-align: center;\">-0.05024</td>\n",
" <td style = \"text-align: center;\">0.015195</td>\n",
" <td style = \"text-align: center;\">-0.080437</td>\n",
" <td style = \"text-align: center;\">-0.020043</td>\n",
" <td style = \"text-align: center;\">DOUBLE LASSO</td>\n",
" <td style = \"text-align: center;\">-0.050001</td>\n",
" <td style = \"text-align: center;\">0.015217</td>\n",
" <td style = \"text-align: center;\">-0.08024</td>\n",
" <td style = \"text-align: center;\">-0.019761</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
Expand All @@ -1460,7 +1460,7 @@
"source": [
"The least square method provides a rather noisy estimate of the speed of convergence. We can not answer the question if poor countries grow faster than rich countries. The least square method does not work when the ratio $p/n$ is large.\n",
"\n",
"In sharp contrast, partialling-out via Lasso provides a more precise estimate. The Lasso based point estimate is $-5\\%$ and the $95\\%$ confidence interval for the (annual) rate of convergence $[-7.8\\%,-2.2\\%]$ only includes negative numbers. This empirical evidence does support the convergence hypothesis."
"In sharp contrast, partialling-out via Lasso provides a more precise estimate. The Lasso based point estimate is $-5\\%$ and the $95\\%$ confidence interval for the (annual) rate of convergence $[-8\\%,-1.9\\%]$ only includes negative numbers. This empirical evidence does support the convergence hypothesis."
]
},
{
Expand All @@ -1487,11 +1487,11 @@
" <td>0.051844</td>\n",
" </tr>\n",
" <tr>\n",
" <th>LASSO</th>\n",
" <td>-0.05024</td>\n",
" <td>0.015195</td>\n",
" <td>-0.080437</td>\n",
" <td>-0.020043</td>\n",
" <th>DOUBLE LASSO</th>\n",
" <td>-0.050001</td>\n",
" <td>0.015217</td>\n",
" <td>-0.08024</td>\n",
" <td>-0.019761</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
Expand Down
Loading

0 comments on commit b7a246b

Please sign in to comment.