зеркало из https://github.com/microsoft/SparseSC.git
repl update
This commit is contained in:
Родитель
7ea4ecbe0c
Коммит
fd8125015c
|
@ -1,7 +1,41 @@
|
|||
cap log close _all
|
||||
log using repl2010.log, replace name(repl2010)
|
||||
|
||||
use smoking.dta, replace
|
||||
tsset state year
|
||||
set seed 1337
|
||||
|
||||
cap program drop show_summ
|
||||
program show_summ
|
||||
cap mat li e(failed_opt_targets)
|
||||
if _rc==0 {
|
||||
mat li e(failed_opt_targets)
|
||||
}
|
||||
di "Pre: Bias and MSE"
|
||||
ttest effect==0 if state!=3 & year<1989
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3)
|
||||
drop pre_mspe
|
||||
|
||||
di "Pre: Bias and MSE (dropping NH outlier)"
|
||||
ttest effect==0 if state!=3 & state!=22 & year<1989
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3 & state!=22)
|
||||
drop pre_mspe
|
||||
|
||||
di "Post: Bias and MSE"
|
||||
ttest effect==0 if state!=3 & year>=1989
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if state!=3
|
||||
drop post_mspe
|
||||
|
||||
di "Post: Bias and MSE (dropping NH outlier)"
|
||||
ttest effect==0 if state!=3 & state!=22 & year>=1989
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if state!=3 & state!=22
|
||||
drop post_mspe
|
||||
end
|
||||
|
||||
//The results from nested most closely match the paper (and allopt doesn't change anything) so use nested
|
||||
/*
|
||||
synth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989)
|
||||
|
@ -9,29 +43,11 @@ synth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsal
|
|||
synth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989) nested allopt
|
||||
*/
|
||||
|
||||
// ----------- Flat V Version --------------//
|
||||
synth_runner cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989) gen_vars customV(1 1 1 1 1 1 1)
|
||||
// no failed targets. mat li e(failed_opt_targets)
|
||||
ttest effect==0 if state!=3 & year<1989 //mean=-.7808893, t-stat: -1.3722 (dof=721)
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3) //234.2147
|
||||
summ pre_mspe //229.1039
|
||||
drop pre_mspe
|
||||
|
||||
ttest effect==0 if state!=3 & year>=1989 //mean=.7111448, t-stat: 0.9186 (dof=455)
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if state!=3 //273.183
|
||||
summ post_mspe //279.4556
|
||||
drop post_mspe
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (f_pre_rmspe f_post_rmspe f_lead f_effect f_cigsale_synth)
|
||||
|
||||
// ----------- Nested Version --------------//
|
||||
synth_runner cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989) nested gen_vars
|
||||
mat li e(failed_opt_targets) //34
|
||||
show_summ
|
||||
//34
|
||||
/*
|
||||
|
||||
|
||||
//Utah=34 has an error with nested
|
||||
//preserve
|
||||
drop if state==3
|
||||
|
@ -44,35 +60,22 @@ could not calculate numerical derivatives
|
|||
flat or discontinuous region encountered
|
||||
r(430);
|
||||
*/
|
||||
//mean=1.076577, t-stat: 2.6233 (dof=702)
|
||||
//119.3197
|
||||
|
||||
ttest effect==0 if state!=3 & year<1989 //mean=1.076577, t-stat: 2.6233 (dof=702)
|
||||
gen pre_mspe = n_pre_rmspe^2
|
||||
summ pre_mspe if (state!=3) //119.3197
|
||||
summ pre_mspe //116.261
|
||||
drop pre_mspe
|
||||
//mean=.5225635, t-stat: 0.8277 (dof=443)
|
||||
//176.859
|
||||
|
||||
ttest effect==0 if state!=3 & year>=1989 //mean=.5225635, t-stat: 0.8277 (dof=443)
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if state!=3 //176.859
|
||||
summ post_mspe //
|
||||
drop post_mspe
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) nested_=
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (n_pre_rmspe n_post_rmspe n_lead n_effect n_cigsale_synth)
|
||||
|
||||
// ----------- Nested Version --------------//
|
||||
// ----------- Fast Version --------------//
|
||||
/*
|
||||
synth_runner cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989) gen_vars
|
||||
show_summ
|
||||
//174.8333
|
||||
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if state!=3 //174.8333
|
||||
summ post_mspe //
|
||||
drop post_mspe
|
||||
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if state!=3 //152.2567
|
||||
summ pre_mspe //148.4591
|
||||
drop pre_mspe
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (f_pre_rmspe f_post_rmspe f_lead f_effect f_cigsale_synth)
|
||||
//152.2567
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) fast_=
|
||||
*/
|
||||
|
||||
// ----------- Version V from SparseSC Fast --------------//
|
||||
|
@ -80,59 +83,97 @@ rename (pre_rmspe post_rmspe lead effect cigsale_synth) (f_pre_rmspe f_post_rmsp
|
|||
loc sparseSC_fast_V = "0.51300713 22.96821089 66.11994103 20.37246761 0.39536433 146.42793943 0.4007635 1.09141769 1.6124491"
|
||||
loc sparseSC_fast_preds = "beer(1986) lnincome(1985) lnincome(1987) lnincome(1988) retprice(1985) age15to24(1988) cigsale(1986) cigsale(1987) cigsale(1988)"
|
||||
synth_runner cigsale `sparseSC_fast_preds', trunit(3) trperiod(1989) customV(`sparseSC_fast_V') gen_vars
|
||||
mat li e(failed_opt_targets) //17, 34
|
||||
show_summ
|
||||
//17, 34
|
||||
|
||||
summ effect if (state!=3)
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if (state!=3) //251.1117
|
||||
summ post_mspe //255.972
|
||||
drop post_mspe
|
||||
//251.1117
|
||||
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3) //217.9936
|
||||
summ pre_mspe //212.6061
|
||||
drop pre_mspe
|
||||
//217.9936
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (nf_pre_rmspe nf_post_rmspe nf_lead nf_effect nf_cigsale_synth)
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) spfast_=
|
||||
*/
|
||||
|
||||
// ----------- Flat V from SparseSC Full --------------//
|
||||
// ----------- Flat V (I_55) V (all potential variables) --------------//
|
||||
loc sparseSC_full_flatV = "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
|
||||
loc sparseSC_full_flatpreds = "beer lnincome retprice age15to24 beer(1984) beer(1985) beer(1986) beer(1987) beer(1988) lnincome(1980) lnincome(1981) lnincome(1982) lnincome(1983) lnincome(1984) lnincome(1985) lnincome(1986) lnincome(1987) lnincome(1988) retprice(1980) retprice(1981) retprice(1982) retprice(1983) retprice(1984) retprice(1985) retprice(1986) retprice(1987) retprice(1988) age15to24(1980) age15to24(1981) age15to24(1982) age15to24(1983) age15to24(1984) age15to24(1985) age15to24(1986) age15to24(1987) age15to24(1988) cigsale(1970) cigsale(1971) cigsale(1972) cigsale(1973) cigsale(1974) cigsale(1975) cigsale(1976) cigsale(1977) cigsale(1978) cigsale(1979) cigsale(1980) cigsale(1981) cigsale(1982) cigsale(1983) cigsale(1984) cigsale(1985) cigsale(1986) cigsale(1987) cigsale(1988)"
|
||||
|
||||
synth_runner cigsale `sparseSC_full_flatpreds', trunit(3) trperiod(1989) customV(`sparseSC_full_flatV') gen_vars
|
||||
show_summ
|
||||
//No failed targets. mat li e(failed_opt_targets) //
|
||||
|
||||
ttest effect==0 if state!=3 & year<1989 //mean=-.3902378, t-stat:-0.6929 (dof=721)
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3) //228.5252
|
||||
summ pre_mspe //224.2566
|
||||
drop pre_mspe
|
||||
//mean=-.3902378, t-stat:-0.6929 (dof=721)
|
||||
//228.5252
|
||||
|
||||
ttest effect==0 if state!=3 & year>=1989 //mean=.3554428, t-stat:0.4614 (dof=455)
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if (state!=3) //270.1838
|
||||
summ post_mspe //278.6318
|
||||
drop post_mspe
|
||||
//mean=.3554428, t-stat:0.4614 (dof=455)
|
||||
//270.1838
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (nn_pre_rmspe nn_post_rmspe nn_lead nn_effect nn_cigsale_synth)
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) flat55_=
|
||||
|
||||
|
||||
// ----------- Flat (I_7) V (all hand-picked variables) --------------//
|
||||
/*
|
||||
synth_runner cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), xperiod(1980(1)1988) trunit(3) trperiod(1989) gen_vars customV(1 1 1 1 1 1 1)
|
||||
show_summ
|
||||
// no failed targets. mat li e(failed_opt_targets)
|
||||
|
||||
//mean=-.7808893, t-stat: -1.3722 (dof=721)
|
||||
//234.2147
|
||||
|
||||
|
||||
//mean=.7111448, t-stat: 0.9186 (dof=455)
|
||||
//273.183
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) flat7_=
|
||||
*/
|
||||
|
||||
// ----------- Version V from SparseSC Full --------------//
|
||||
loc sparseSC_full_V = "5.62581428e-06 1.67298271e-04 1.25447705e-04 2.83218864e-05 1.20684653e-04 2.90538206e-05 1.68471635e-04 1.91157505e-04 1.95644283e-04 2.87258604e-04 4.25739528e-04 4.62630652e-04 6.40482407e-04"
|
||||
loc sparseSC_full_preds = "cigsale(1976) cigsale(1977) cigsale(1978) cigsale(1979) cigsale(1980) cigsale(1981) cigsale(1982) cigsale(1983) cigsale(1984) cigsale(1985) cigsale(1986) cigsale(1987) cigsale(1988)"
|
||||
synth_runner cigsale `sparseSC_full_preds', trunit(3) trperiod(1989) customV(`sparseSC_full_V') gen_vars
|
||||
mat li e(failed_opt_targets) //22, 34
|
||||
show_summ
|
||||
//22, 34
|
||||
|
||||
ttest effect==0 if state!=3 & year<1989 //mean=-.1812726, t-stat:-0.9543 (dof=683)
|
||||
gen pre_mspe = pre_rmspe^2
|
||||
summ pre_mspe if (state!=3) //24.69864
|
||||
summ pre_mspe //24.18579
|
||||
drop pre_mspe
|
||||
//mean=-.1812726, t-stat:-0.9543 (dof=683)
|
||||
//24.69864
|
||||
|
||||
ttest effect==0 if state!=3 & year>=1989 //mean=.3479216, t-stat:0.5997 (dof=431)
|
||||
gen post_mspe = post_rmspe^2
|
||||
summ post_mspe if (state!=3) //145.1905
|
||||
summ post_mspe //153.6692
|
||||
drop post_mspe
|
||||
//mean=.3479216, t-stat:0.5997 (dof=431)
|
||||
//145.1905
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) spfull_=
|
||||
|
||||
// ----------- End --------------//
|
||||
|
||||
preserve
|
||||
replace nested_effect = abs(nested_effect)
|
||||
replace flat55_effect = abs(flat55_effect)
|
||||
replace spfull_effect = abs(spfull_effect)
|
||||
collapse (max) *_effect, by(year)
|
||||
|
||||
summ *_effect if year<1989
|
||||
summ *_effect if year>=1989
|
||||
restore
|
||||
|
||||
|
||||
keep state year cigsale *effect
|
||||
save smoking_statafits.dta, replace
|
||||
|
||||
log close repl2010
|
||||
|
||||
/*
|
||||
use smoking_statafits.dta, clear
|
||||
*/
|
||||
loc pe_varnames "nested flat55 spfull"
|
||||
loc pe_titles `""Standard SC" "Standard SC (v=I_55)" "Standard SC (v=SparseSC)""'
|
||||
loc pe_n : word count `pe_varnames'
|
||||
forvalues i=1/`pe_n' {
|
||||
loc pe_varname : word `i' of `pe_varnames'
|
||||
loc pe_title : word `i' of `pe_titles'
|
||||
xtline `pe_varname'_effect if state!=3, overlay xline(1989) legend(off) name("`pe_varname'", replace) title("Prediction errors: `pe_title'") ytitle("Cigarette sales (packs)/capita") xtitle("Year") caption("Control units only") yscale(r(-70, 155))
|
||||
graph export "standard_`pe_varname'_pe.eps", as(eps) preview(on) replace
|
||||
}
|
||||
|
||||
use smoking_sparsesc.dta, clear
|
||||
xtset state year
|
||||
xtline cigsale if state!=3, overlay xline(1989) legend(off) name("sparsesc", replace) title("Prediction errors: SparseSC") ytitle("Cigarette sales (packs)/capita") xtitle("Year") caption("Control units only") yscale(r(-70, 155))
|
||||
graph export "sparsesc_pe.eps", as(eps) preview(on) replace
|
||||
|
||||
rename (pre_rmspe post_rmspe lead effect cigsale_synth) (nn_pre_rmspe nn_post_rmspe nn_lead nn_effect nn_cigsale_synth)
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pickle\n",
|
||||
"import random\n",
|
||||
"import datetime\n",
|
||||
"\n",
|
||||
"import scipy\n",
|
||||
"import numpy as np\n",
|
||||
|
@ -21,7 +22,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -31,7 +32,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -40,7 +41,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -58,7 +59,7 @@
|
|||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th></th>\n <th>cigsale</th>\n <th>lnincome</th>\n <th>beer</th>\n <th>age15to24</th>\n <th>retprice</th>\n </tr>\n <tr>\n <th>state</th>\n <th>year</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th rowspan=\"5\" valign=\"top\">Alabama</th>\n <th>1970</th>\n <td>89.800003</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>0.178862</td>\n <td>39.599998</td>\n </tr>\n <tr>\n <th>1971</th>\n <td>95.400002</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>0.179928</td>\n <td>42.700001</td>\n </tr>\n <tr>\n <th>1972</th>\n <td>101.099998</td>\n <td>9.498476</td>\n <td>NaN</td>\n <td>0.180994</td>\n <td>42.299999</td>\n </tr>\n <tr>\n <th>1973</th>\n <td>102.900002</td>\n <td>9.550107</td>\n <td>NaN</td>\n <td>0.182060</td>\n <td>42.099998</td>\n </tr>\n <tr>\n <th>1974</th>\n <td>108.199997</td>\n <td>9.537163</td>\n <td>NaN</td>\n <td>0.183126</td>\n <td>43.099998</td>\n </tr>\n </tbody>\n</table>\n</div>"
|
||||
},
|
||||
"metadata": {},
|
||||
"execution_count": 34
|
||||
"execution_count": 4
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
@ -70,7 +71,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -118,7 +119,7 @@
|
|||
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead tr th {\n text-align: left;\n }\n\n .dataframe thead tr:last-of-type th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr>\n <th></th>\n <th colspan=\"21\" halign=\"left\">cigsale</th>\n </tr>\n <tr>\n <th>year</th>\n <th>1970</th>\n <th>1971</th>\n <th>1972</th>\n <th>1973</th>\n <th>1974</th>\n <th>1975</th>\n <th>1976</th>\n <th>1977</th>\n <th>1978</th>\n <th>1979</th>\n <th>...</th>\n <th>1991</th>\n <th>1992</th>\n <th>1993</th>\n <th>1994</th>\n <th>1995</th>\n <th>1996</th>\n <th>1997</th>\n <th>1998</th>\n <th>1999</th>\n <th>2000</th>\n </tr>\n <tr>\n <th>state</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Alabama</th>\n <td>89.800003</td>\n <td>95.400002</td>\n <td>101.099998</td>\n <td>102.900002</td>\n <td>108.199997</td>\n <td>111.699997</td>\n <td>116.199997</td>\n <td>117.099998</td>\n <td>123.000000</td>\n <td>121.400002</td>\n <td>...</td>\n <td>107.900002</td>\n <td>109.099998</td>\n <td>108.500000</td>\n <td>107.099998</td>\n <td>102.599998</td>\n <td>101.400002</td>\n <td>104.900002</td>\n <td>106.199997</td>\n <td>100.699997</td>\n <td>96.199997</td>\n </tr>\n <tr>\n <th>Arkansas</th>\n <td>100.300003</td>\n <td>104.099998</td>\n <td>103.900002</td>\n <td>108.000000</td>\n <td>109.699997</td>\n <td>114.800003</td>\n <td>119.099998</td>\n <td>122.599998</td>\n <td>127.300003</td>\n <td>126.500000</td>\n <td>...</td>\n <td>116.800003</td>\n <td>126.000000</td>\n <td>113.800003</td>\n <td>108.800003</td>\n <td>113.000000</td>\n <td>110.699997</td>\n <td>108.699997</td>\n <td>109.500000</td>\n <td>104.800003</td>\n <td>99.400002</td>\n </tr>\n <tr>\n <th>California</th>\n <td>123.000000</td>\n <td>121.000000</td>\n <td>123.500000</td>\n <td>124.400002</td>\n <td>126.699997</td>\n <td>127.099998</td>\n <td>128.000000</td>\n <td>126.400002</td>\n <td>126.099998</td>\n <td>121.900002</td>\n <td>...</td>\n <td>68.699997</td>\n <td>67.500000</td>\n <td>63.400002</td>\n <td>58.599998</td>\n <td>56.400002</td>\n <td>54.500000</td>\n <td>53.799999</td>\n <td>52.299999</td>\n <td>47.200001</td>\n <td>41.599998</td>\n </tr>\n <tr>\n <th>Colorado</th>\n <td>124.800003</td>\n <td>125.500000</td>\n <td>134.300003</td>\n <td>137.899994</td>\n <td>132.800003</td>\n <td>131.000000</td>\n <td>134.199997</td>\n <td>132.000000</td>\n <td>129.199997</td>\n <td>131.500000</td>\n <td>...</td>\n <td>90.199997</td>\n <td>88.300003</td>\n <td>88.599998</td>\n <td>89.099998</td>\n <td>85.400002</td>\n <td>83.099998</td>\n <td>81.300003</td>\n <td>81.199997</td>\n <td>79.599998</td>\n <td>73.000000</td>\n </tr>\n <tr>\n <th>Connecticut</th>\n <td>120.000000</td>\n <td>117.599998</td>\n <td>110.800003</td>\n <td>109.300003</td>\n <td>112.400002</td>\n <td>110.199997</td>\n <td>113.400002</td>\n <td>117.300003</td>\n <td>117.500000</td>\n <td>117.400002</td>\n <td>...</td>\n <td>86.699997</td>\n <td>83.500000</td>\n <td>79.099998</td>\n <td>76.599998</td>\n <td>79.300003</td>\n <td>76.000000</td>\n <td>75.900002</td>\n <td>75.500000</td>\n <td>73.400002</td>\n <td>71.400002</td>\n </tr>\n </tbody>\n</table>\n<p>5 rows × 31 columns</p>\n</div>"
|
||||
},
|
||||
"metadata": {},
|
||||
"execution_count": 35
|
||||
"execution_count": 5
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
@ -129,7 +130,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -151,7 +152,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -174,7 +175,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -190,7 +191,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -203,7 +204,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -218,7 +219,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -232,7 +233,7 @@
|
|||
" \n",
|
||||
" print(X_Y_pre_names_arr[np.diag(full_fit.V)>0])\n",
|
||||
"\n",
|
||||
" def print_seg_info(arr, seg_name)\n",
|
||||
" def print_seg_info(arr, seg_name):\n",
|
||||
" print(\"Avg bias \" + seg_name + \": \" + str(arr.mean()))\n",
|
||||
" print(scipy.stats.ttest_1samp(arr.flatten(), popmean=0)) \n",
|
||||
" print(\"Avg MSE \" + seg_name + \": \" + str(np.mean(np.power(arr, 2))) )\n",
|
||||
|
@ -285,7 +286,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"execution_count": 15,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
|
@ -294,7 +295,8 @@
|
|||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"Done!\n"
|
||||
"Start time: 2021-01-01 14:17:04\n",
|
||||
"End time: 2021-01-01 14:34:29\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -318,14 +320,14 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"V: [0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 5.62581428e-06 1.67298271e-04\n 1.25447705e-04 2.83218864e-05 1.20684653e-04 2.90538206e-05\n 1.68471635e-04 1.91157505e-04 1.95644283e-04 2.87258604e-04\n 4.25739528e-04 4.62630652e-04 6.40482407e-04]\nV>0: [5.62581428e-06 1.67298271e-04 1.25447705e-04 2.83218864e-05\n 1.20684653e-04 2.90538206e-05 1.68471635e-04 1.91157505e-04\n 1.95644283e-04 2.87258604e-04 4.25739528e-04 4.62630652e-04\n 6.40482407e-04]\n#V>0: 13\nAvg bias pre: 0.0775621971135751\nTtest_1sampResult(statistic=0.15231397793810575, pvalue=0.8789819126134504)\nAvg MSE pre: 186.96913693932575\nAvg effect post: 0.036591103495526384\nTtest_1sampResult(statistic=0.06540254251104247, pvalue=0.9478822253243375)\nAvg MSE post: 142.42204905739652\n['cigsale(1976)' 'cigsale(1977)' 'cigsale(1978)' 'cigsale(1979)'\n 'cigsale(1980)' 'cigsale(1981)' 'cigsale(1982)' 'cigsale(1983)'\n 'cigsale(1984)' 'cigsale(1985)' 'cigsale(1986)' 'cigsale(1987)'\n 'cigsale(1988)']\n"
|
||||
"V: [0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 5.62581428e-06 1.67298271e-04\n 1.25447705e-04 2.83218864e-05 1.20684653e-04 2.90538206e-05\n 1.68471635e-04 1.91157505e-04 1.95644283e-04 2.87258604e-04\n 4.25739528e-04 4.62630652e-04 6.40482407e-04]\nV>0: [5.62581428e-06 1.67298271e-04 1.25447705e-04 2.83218864e-05\n 1.20684653e-04 2.90538206e-05 1.68471635e-04 1.91157505e-04\n 1.95644283e-04 2.87258604e-04 4.25739528e-04 4.62630652e-04\n 6.40482407e-04]\n#V>0: 13\n['cigsale(1976)' 'cigsale(1977)' 'cigsale(1978)' 'cigsale(1979)'\n 'cigsale(1980)' 'cigsale(1981)' 'cigsale(1982)' 'cigsale(1983)'\n 'cigsale(1984)' 'cigsale(1985)' 'cigsale(1986)' 'cigsale(1987)'\n 'cigsale(1988)']\nAvg bias pre: 0.07756219711357981\nTtest_1sampResult(statistic=0.15231397793811494, pvalue=0.8789819126134432)\nAvg MSE pre: 186.969136939326\nAvg max abs val pre:43.94306313035026\nAvg bias post: 0.036591103495529125\nTtest_1sampResult(statistic=0.0654025425110474, pvalue=0.9478822253243336)\nAvg MSE post: 142.42204905739632\nAvg max abs val post:28.952062858014358\nAvg bias pre (no-NH): -1.0717637082830929\nTtest_1sampResult(statistic=-2.592180790152355, pvalue=0.00973536548850398)\nAvg MSE pre (no-NH): 121.15513896073007\nAvg max abs val pre (no-NH):31.277865279231538\nAvg bias post (no-NH): 0.1280987232307059\nTtest_1sampResult(statistic=0.22671379737775588, pvalue=0.8207508739680021)\nAvg MSE post (no-NH): 141.44506906760296\nAvg max abs val post (no-NH):28.952062858014358\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -336,14 +338,14 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
" |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
|
||||
" |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -354,14 +356,14 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"V: [0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 5.62581428e-06 1.67298271e-04\n 1.25447705e-04 2.83218864e-05 1.20684653e-04 2.90538206e-05\n 1.68471635e-04 1.91157505e-04 1.95644283e-04 2.87258604e-04\n 4.25739528e-04 4.62630652e-04 6.40482407e-04]\nV>0: [5.62581428e-06 1.67298271e-04 1.25447705e-04 2.83218864e-05\n 1.20684653e-04 2.90538206e-05 1.68471635e-04 1.91157505e-04\n 1.95644283e-04 2.87258604e-04 4.25739528e-04 4.62630652e-04\n 6.40482407e-04]\n#V>0: 13\nAvg bias pre: -1.6187760995035356\nTtest_1sampResult(statistic=-3.4419861964346423, pvalue=0.0006107737173349461)\nAvg MSE pre: 162.0946915406102\nAvg effect post: -0.15200904377719812\nTtest_1sampResult(statistic=-0.30910995445207323, pvalue=0.7573793806908214)\nAvg MSE post: 110.05643980497922\n['cigsale(1976)' 'cigsale(1977)' 'cigsale(1978)' 'cigsale(1979)'\n 'cigsale(1980)' 'cigsale(1981)' 'cigsale(1982)' 'cigsale(1983)'\n 'cigsale(1984)' 'cigsale(1985)' 'cigsale(1986)' 'cigsale(1987)'\n 'cigsale(1988)']\n"
|
||||
"V: [0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n 0.00000000e+00 0.00000000e+00 5.62581428e-06 1.67298271e-04\n 1.25447705e-04 2.83218864e-05 1.20684653e-04 2.90538206e-05\n 1.68471635e-04 1.91157505e-04 1.95644283e-04 2.87258604e-04\n 4.25739528e-04 4.62630652e-04 6.40482407e-04]\nV>0: [5.62581428e-06 1.67298271e-04 1.25447705e-04 2.83218864e-05\n 1.20684653e-04 2.90538206e-05 1.68471635e-04 1.91157505e-04\n 1.95644283e-04 2.87258604e-04 4.25739528e-04 4.62630652e-04\n 6.40482407e-04]\n#V>0: 13\n['cigsale(1976)' 'cigsale(1977)' 'cigsale(1978)' 'cigsale(1979)'\n 'cigsale(1980)' 'cigsale(1981)' 'cigsale(1982)' 'cigsale(1983)'\n 'cigsale(1984)' 'cigsale(1985)' 'cigsale(1986)' 'cigsale(1987)'\n 'cigsale(1988)']\nAvg bias pre: -0.7350711981015192\nTtest_1sampResult(statistic=-1.3801169113351313, pvalue=0.16797842226970588)\nAvg MSE pre: 205.07282757064715\nAvg max abs val pre:44.605702450400905\nAvg bias post: -0.21665792297898678\nTtest_1sampResult(statistic=-0.3608685113352452, pvalue=0.7183652274687031)\nAvg MSE post: 164.05401118717884\nAvg max abs val post:30.973639170328777\nAvg bias pre (no-NH): -1.9151725931832326\nTtest_1sampResult(statistic=-4.336260426835046, pvalue=1.661526771635277e-05)\nAvg MSE pre (no-NH): 140.60533540082383\nAvg max abs val pre (no-NH):31.151243109452096\nAvg bias post (no-NH): -0.16072957150570982\nTtest_1sampResult(statistic=-0.26377389204835666, pvalue=0.7920768075601825)\nAvg MSE post (no-NH): 164.51287385286167\nAvg max abs val post (no-NH):30.973639170328777\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -372,7 +374,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -383,7 +385,7 @@
|
|||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"execution_count": 20
|
||||
"execution_count": 21
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
@ -392,11 +394,11 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"honest_predictions_df = pd.DataFrame(honest_predictions, columns=Y_cols, index=control_units).stack(level=\"year\")\n",
|
||||
"honest_predictions_df = pd.DataFrame(Y[control_units,:] - honest_predictions, columns=Y_cols, index=pd.Index(np.array(control_units)+1, name=\"state\")).stack(level=\"year\")\n",
|
||||
"honest_predictions_df.to_stata(\"smoking_sparsesc.dta\")"
|
||||
]
|
||||
},
|
||||
|
@ -492,7 +494,7 @@
|
|||
"display_name": "Python 3.6.8 64-bit ('SparseSC_36': conda)",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "a874c5cea27404d4932ec17617c98c8f4631437eb5052d1551a7b7bc79fe6733"
|
||||
"hash": "d5e4199e480c30e65d4fb20d3cd9d777774bdb7741bde6dbd2b401b3aff7fdac"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче