def mte_and_cof_int_par(rslt, init_dict, data, college_years): """ This function returns the parametric MTE divided by the number of college years, which represents the returns per YEAR of post-secondary schooling. 90 percent confidence intervals are computed analytically. Parameters ---------- rslt: dict Result dictionary containing parameters for the estimation process. init_dict: dict Initialization dictionary containing parameters for the estimation process. data: pandas.DataFrame Data set containing the observables (explanatory and outcome variables) analyzed in the generalized Roy framework. college_years: int, default is 4 Average duration of college degree. The MTE plotted will thus refer to the returns per one year of college education. """ # Define quantiles of u_D (unobserved resistance to treatment) quantiles = [0.0001] + np.arange(0.01, 1.0, 0.01).tolist() + [0.9999] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, data, quantiles) mte = [i / college_years for i in mte] con_u, con_d = calculate_cof_int(rslt, init_dict, data, mte, quantiles) return quantiles, mte, con_u, con_d
def plot_est_mte(rslt, file): """This function calculates the marginal treatment effect for different quartiles of the unobservable V. ased on the calculation results.""" init_dict = read(file) data_frame = pd.read_pickle(init_dict['ESTIMATION']['file']) # Define the Quantiles and read in the original results quantiles = [0.0001] + np.arange(0.01, 1., 0.01).tolist() + [0.9999] mte_ = json.load(open('data/mte_original.json', 'r')) mte_original = mte_[1] mte_original_d = mte_[0] mte_original_u = mte_[2] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, init_dict, data_frame, quantiles) mte = [i / 4 for i in mte] mte_up, mte_d = calculate_cof_int(rslt, init_dict, data_frame, mte, quantiles) # Plot both curves ax = plt.figure(figsize=(17.5, 10)).add_subplot(111) ax.set_ylabel(r"$B^{MTE}$", fontsize=24) ax.set_xlabel("$u_D$", fontsize=24) ax.tick_params(axis='both', which='major', labelsize=18) ax.plot(quantiles, mte, label='grmpy $B^{MTE}$', color='blue', linewidth=4) ax.plot(quantiles, mte_up, color='blue', linestyle=':', linewidth=3) ax.plot(quantiles, mte_d, color='blue', linestyle=':', linewidth=3) ax.plot(quantiles, mte_original, label='original$B^{MTE}$', color='orange', linewidth=4) ax.plot(quantiles, mte_original_d, color='orange', linestyle=':', linewidth=3) ax.plot(quantiles, mte_original_u, color='orange', linestyle=':', linewidth=3) ax.set_ylim([-0.41, 0.51]) ax.set_xlim([-0.005, 1.005]) blue_patch = mpatches.Patch(color='blue', label='original $B^{MTE}$') orange_patch = mpatches.Patch(color='orange', label='grmpy $B^{MTE}$') plt.legend(handles=[blue_patch, orange_patch], prop={'size': 16}) plt.show() return mte
def parametric_mte(rslt, file): """This function calculates the marginal treatment effect for different quartiles of the unobservable V based on the calculation results.""" init_dict = read(file) data_frame = pd.read_pickle(init_dict["ESTIMATION"]["file"]) # Define quantiles and read in the original results quantiles = [0.0001] + np.arange(0.01, 1.0, 0.01).tolist() + [0.9999] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, data_frame, quantiles) mte_up, mte_d = calculate_cof_int(rslt, init_dict, data_frame, mte, quantiles) return quantiles, mte, mte_up, mte_d
def mte_and_cof_int_par(rslt, init_dict, data, college_years): """This function returns the parametric MTE divided by the number of college years, which represents the returns per YEAR of post-secondary schooling. 90 percent confidence intervals are computed analytically. """ # Define quantiles of u_D (unobserved resistance to treatment) quantiles = [0.0001] + np.arange(0.01, 1.0, 0.01).tolist() + [0.9999] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, data, quantiles) mte = [i / college_years for i in mte] con_u, con_d = calculate_cof_int(rslt, init_dict, data, mte, quantiles) return quantiles, mte, con_u, con_d
def plot_est_mte(rslt, init_dict, data_frame): """This function calculates the marginal treatment effect for different quartiles of the unobservable V. ased on the calculation results.""" # Define the Quantiles and read in the original results quantiles = [0.0001] + np.arange(0.01, 1.0, 0.01).tolist() + [0.9999] mte_ = json.load(open("mte_original.json")) mte_original = mte_[1] mte_original_d = mte_[0] mte_original_u = mte_[2] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, data_frame, quantiles) mte = [i / 4 for i in mte] mte_up, mte_d = calculate_cof_int(rslt, init_dict, data_frame, mte, quantiles) # Plot both curves ax = plt.figure(figsize=(14, 6)) ax1 = ax.add_subplot(121) ax1.set_ylabel(r"$B^{MTE}$") ax1.set_xlabel("$u_D$") (l1, ) = ax1.plot(quantiles, mte, color="blue") ax1.plot(quantiles, mte_up, color="blue", linestyle=":") ax1.plot(quantiles, mte_d, color="blue", linestyle=":") ax1.set_ylim([-0.4, 0.5]) ax2 = ax.add_subplot(122) ax2.set_ylabel(r"$B^{MTE}$") ax2.set_xlabel("$u_D$") (l4, ) = ax2.plot(quantiles, mte_original, color="orange") ax2.plot(quantiles, mte_original_d, color="orange", linestyle=":") ax2.plot(quantiles, mte_original_u, color="orange", linestyle=":") ax2.set_ylim([-0.4, 0.5]) plt.legend([l1, l4], ["grmpy $B^{MTE}$", "original $B^{MTE}$"], prop={"size": 18}) plt.tight_layout() plt.savefig("fig-marginal-benefit-parametric-replication.png", dpi=300) return mte
def plot_est_mte(rslt, init_dict, data_frame): """This function calculates the marginal treatment effect for different quartiles of the unobservable V. ased on the calculation results.""" # Define the Quantiles and read in the original results quantiles = [0.0001] + np.arange(0.01, 1., 0.01).tolist() + [0.9999] mte_ = json.load(open('mte_original.json', 'r')) mte_original = mte_[1] mte_original_d = mte_[0] mte_original_u = mte_[2] # Calculate the MTE and confidence intervals mte = calculate_mte(rslt, init_dict, data_frame, quantiles) mte = [i / 4 for i in mte] mte_up, mte_d = calculate_cof_int(rslt, init_dict, data_frame, mte, quantiles) # Plot both curveslscpu | grep MHz ax = plt.figure().add_subplot(111) ax.set_ylabel(r"$B^{MTE}$") ax.set_xlabel("$u_S$") ax.plot(quantiles, mte, label='grmpy MTE', color='blue') ax.plot(quantiles, mte_up, color='blue', linestyle=':') ax.plot(quantiles, mte_d, color='blue', linestyle=':') ax.plot(quantiles, mte_original, label='original MTE', color='red') ax.plot(quantiles, mte_original_d, color='red', linestyle=':') ax.plot(quantiles, mte_original_u, color='red', linestyle=':') ax.set_ylim([-0.4, 0.5]) plt.legend() plt.tight_layout() plt.savefig('fig-marginal-benefit-parametric-replication.png') return mte