├── Tutorials ├── DataFiles │ ├── ex2.csv │ ├── ex1.csv │ ├── out2.pkl │ ├── dict1.pkl │ ├── ex5.csv │ ├── out.csv │ ├── csv_mindex.csv │ ├── ex4.csv │ ├── geyser.csv │ ├── penny.csv │ ├── Econ381totpts.txt │ ├── emat.csv │ └── iris.csv ├── git_tutorial.pdf ├── Images │ ├── BokehSlide.png │ ├── glyphexamp.png │ ├── ChernoffFaces.png │ └── OldFaithfulCDF.png └── LaTeX │ ├── pencildrawing.png │ ├── LaTeX_tutorial.pdf │ ├── LaTeX_probset_template.pdf │ └── LaTeX_probset_template.tex ├── Slides ├── OGintro.pdf └── furman20171103ppt.pdf ├── Midterm └── Midterm.pdf ├── ProblemSets ├── PS1 │ └── PS1.pdf ├── PS2 │ └── PS2.pdf ├── PS3 │ └── PS3.pdf ├── PS4 │ └── PS4.pdf ├── PS5 │ └── PS5.pdf ├── PS6 │ └── PS6.pdf ├── PS7 │ ├── PS7.pdf │ ├── pop_data.csv │ └── mort_rates2011.csv ├── PS8 │ └── PS8.pdf └── PS9 │ ├── PS9.pdf │ └── tax_data.pkl ├── References └── OGtext_bib.pdf ├── Students ├── Fiona │ ├── PS4 │ │ ├── fig1.png │ │ ├── PS4_Fiona.pdf │ │ ├── ellipse.py │ │ ├── stitch.py │ │ └── PS4_Fiona.tex │ ├── PS7 │ │ ├── PS7.pdf │ │ ├── PS7_Fiona.pdf │ │ ├── images_dem │ │ │ ├── imm_rate_20.png │ │ │ ├── imm_rate_80.png │ │ │ ├── fert_rate_100.png │ │ │ ├── fert_rate_20.png │ │ │ ├── fert_rate_80.png │ │ │ ├── imm_rate_100.png │ │ │ ├── mort_rate_100.png │ │ │ ├── mort_rate_20.png │ │ │ ├── mort_rate_80.png │ │ │ ├── population_dist.png │ │ │ ├── population_growth.png │ │ │ └── population_dist_times.png │ │ ├── driver.py │ │ ├── pop_data.csv │ │ ├── PS7_Fiona.tex │ │ └── mort_rates2011.csv │ ├── PS1 │ │ ├── PS1_Fiona.pdf │ │ └── PS1_Fiona.tex │ ├── PS2 │ │ ├── PS2_Fiona.pdf │ │ ├── figure_0.png │ │ ├── figure_1.png │ │ ├── figure_2.png │ │ ├── figure_3.png │ │ ├── figure_4.png │ │ ├── TPI.py │ │ ├── driver.py │ │ ├── problem1.py │ │ ├── SS.py │ │ └── PS2_Fiona.tex │ ├── PS3 │ │ ├── PS3_Fiona.pdf │ │ ├── images │ │ │ ├── n1.png │ │ │ ├── n2.png │ │ │ ├── Kpath.png │ │ │ ├── Ypath.png │ │ │ ├── bpath.png │ │ │ ├── cpath.png │ │ │ ├── rpath.png │ │ │ ├── wpath.png │ │ │ ├── b15path.png │ │ │ └── C_aggr_path.png │ │ ├── TPI2.py │ │ ├── SS.py │ │ └── PS3_Fiona.tex │ ├── PS5 │ │ ├── PS5_Fiona.pdf │ │ ├── images_SS │ │ │ ├── ss_bc.png │ │ │ └── ss_n.png │ │ ├── images_TPI │ │ │ ├── bpath.png │ │ │ ├── cpath.png │ │ │ ├── npath.png │ │ │ ├── tpi_C.png │ │ │ ├── tpi_K.png │ │ │ ├── tpi_L.png │ │ │ ├── tpi_Y.png │ │ │ ├── tpi_r.png │ │ │ └── tpi_w.png │ │ ├── output_tpi.csv │ │ ├── output_ss.csv │ │ ├── driver.py │ │ ├── SS.py │ │ ├── PS5_Fiona.tex │ │ └── utils.py │ ├── PS6 │ │ ├── PS6_Fiona.pdf │ │ ├── images │ │ │ ├── Kpath.png │ │ │ ├── Ypath.png │ │ │ ├── rpath.png │ │ │ ├── ss_bc.png │ │ │ ├── wpath.png │ │ │ ├── BQpath.png │ │ │ ├── b25path.png │ │ │ ├── ss_bc1.png │ │ │ ├── C_aggr_path.png │ │ │ ├── distribution.png │ │ │ └── bq_pct_quantile.png │ │ ├── .idea │ │ │ └── vcs.xml │ │ ├── problem2.csv │ │ ├── PS6_Fiona.tex │ │ ├── script.py │ │ ├── utils.py │ │ └── SS.py │ └── PS8 │ │ ├── images_ss_tpi │ │ └── ss_bc.png │ │ ├── .idea │ │ ├── misc.xml │ │ ├── inspectionProfiles │ │ │ └── profiles_settings.xml │ │ ├── modules.xml │ │ └── PS7.iml │ │ ├── pop_data.csv │ │ ├── utils.py │ │ ├── mort_rates2011.csv │ │ └── SS.py └── Sophia │ ├── ps3 │ ├── bplot.png │ ├── kplot.png │ ├── rplot.png │ ├── ss_bc1.png │ ├── ss_bc2.png │ ├── wplot.png │ └── ps3_writeup.pdf │ ├── ps1 │ ├── PS1_writeup.pdf │ └── PS1_writeup.tex │ ├── ps4 │ ├── ps4_writeup.pdf │ ├── images │ │ ├── MU_c_stitched.png │ │ ├── MU_n_stitched.png │ │ └── Marginal_Disutility_ellip.png │ ├── ellip_util.py │ ├── ps4_writeup.tex │ └── Households.py │ ├── ps5 │ ├── images │ │ ├── ss_n.png │ │ ├── bpath.png │ │ ├── cpath.png │ │ ├── npath.png │ │ ├── ss_bc.png │ │ ├── tpi_C.png │ │ ├── tpi_K.png │ │ ├── tpi_L.png │ │ ├── tpi_Y.png │ │ ├── tpi_r.png │ │ ├── tpi_w.png │ │ └── MU_c_stitched.png │ ├── ps5_writeup.pdf │ ├── firms.py │ ├── execute.py │ ├── aggregates.py │ ├── SS.py │ └── ps5_writeup.tex │ └── ps8 │ ├── pop_data.csv │ └── mort_rates2011.csv └── .gitignore /Tutorials/DataFiles/ex2.csv: -------------------------------------------------------------------------------- 1 | 1,2,3,4,hello 2 | 5,6,7,8,world 3 | 9,10,11,12,foo -------------------------------------------------------------------------------- /Slides/OGintro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Slides/OGintro.pdf -------------------------------------------------------------------------------- /Midterm/Midterm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Midterm/Midterm.pdf -------------------------------------------------------------------------------- /Tutorials/DataFiles/ex1.csv: -------------------------------------------------------------------------------- 1 | a,b,c,d,message 2 | 1,2,3,4,hello 3 | 5,6,7,8,world 4 | 9,10,11,12,foo -------------------------------------------------------------------------------- /ProblemSets/PS1/PS1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS1/PS1.pdf -------------------------------------------------------------------------------- /ProblemSets/PS2/PS2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS2/PS2.pdf -------------------------------------------------------------------------------- /ProblemSets/PS3/PS3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS3/PS3.pdf -------------------------------------------------------------------------------- /ProblemSets/PS4/PS4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS4/PS4.pdf -------------------------------------------------------------------------------- /ProblemSets/PS5/PS5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS5/PS5.pdf -------------------------------------------------------------------------------- /ProblemSets/PS6/PS6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS6/PS6.pdf -------------------------------------------------------------------------------- /ProblemSets/PS7/PS7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS7/PS7.pdf -------------------------------------------------------------------------------- /ProblemSets/PS8/PS8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS8/PS8.pdf -------------------------------------------------------------------------------- /ProblemSets/PS9/PS9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS9/PS9.pdf -------------------------------------------------------------------------------- /References/OGtext_bib.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/References/OGtext_bib.pdf -------------------------------------------------------------------------------- /ProblemSets/PS9/tax_data.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/ProblemSets/PS9/tax_data.pkl -------------------------------------------------------------------------------- /Slides/furman20171103ppt.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Slides/furman20171103ppt.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS4/fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS4/fig1.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/PS7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/PS7.pdf -------------------------------------------------------------------------------- /Tutorials/DataFiles/out2.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/DataFiles/out2.pkl -------------------------------------------------------------------------------- /Tutorials/git_tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/git_tutorial.pdf -------------------------------------------------------------------------------- /Students/Sophia/ps3/bplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/bplot.png -------------------------------------------------------------------------------- /Students/Sophia/ps3/kplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/kplot.png -------------------------------------------------------------------------------- /Students/Sophia/ps3/rplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/rplot.png -------------------------------------------------------------------------------- /Students/Sophia/ps3/ss_bc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/ss_bc1.png -------------------------------------------------------------------------------- /Students/Sophia/ps3/ss_bc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/ss_bc2.png -------------------------------------------------------------------------------- /Students/Sophia/ps3/wplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/wplot.png -------------------------------------------------------------------------------- /Tutorials/DataFiles/dict1.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/DataFiles/dict1.pkl -------------------------------------------------------------------------------- /Tutorials/DataFiles/ex5.csv: -------------------------------------------------------------------------------- 1 | something,a,b,c,d,message 2 | one,1,2,3,4,NA 3 | two,5,6,,8,world 4 | three,9,10,11,12,foo -------------------------------------------------------------------------------- /Students/Fiona/PS1/PS1_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS1/PS1_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS2/PS2_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/PS2_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS2/figure_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/figure_0.png -------------------------------------------------------------------------------- /Students/Fiona/PS2/figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/figure_1.png -------------------------------------------------------------------------------- /Students/Fiona/PS2/figure_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/figure_2.png -------------------------------------------------------------------------------- /Students/Fiona/PS2/figure_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/figure_3.png -------------------------------------------------------------------------------- /Students/Fiona/PS2/figure_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS2/figure_4.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/PS3_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/PS3_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/n1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/n1.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/n2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/n2.png -------------------------------------------------------------------------------- /Students/Fiona/PS4/PS4_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS4/PS4_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS5/PS5_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/PS5_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS6/PS6_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/PS6_Fiona.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS7/PS7_Fiona.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/PS7_Fiona.pdf -------------------------------------------------------------------------------- /Tutorials/Images/BokehSlide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/Images/BokehSlide.png -------------------------------------------------------------------------------- /Tutorials/Images/glyphexamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/Images/glyphexamp.png -------------------------------------------------------------------------------- /Tutorials/LaTeX/pencildrawing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/LaTeX/pencildrawing.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/Kpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/Kpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/Ypath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/Ypath.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/bpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/bpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/cpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/cpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/rpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/rpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/wpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/wpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/Kpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/Kpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/Ypath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/Ypath.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/rpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/rpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/ss_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/ss_bc.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/wpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/wpath.png -------------------------------------------------------------------------------- /Students/Sophia/ps1/PS1_writeup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps1/PS1_writeup.pdf -------------------------------------------------------------------------------- /Students/Sophia/ps3/ps3_writeup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps3/ps3_writeup.pdf -------------------------------------------------------------------------------- /Students/Sophia/ps4/ps4_writeup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps4/ps4_writeup.pdf -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/ss_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/ss_n.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/ps5_writeup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/ps5_writeup.pdf -------------------------------------------------------------------------------- /Tutorials/Images/ChernoffFaces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/Images/ChernoffFaces.png -------------------------------------------------------------------------------- /Tutorials/Images/OldFaithfulCDF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/Images/OldFaithfulCDF.png -------------------------------------------------------------------------------- /Tutorials/LaTeX/LaTeX_tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/LaTeX/LaTeX_tutorial.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/b15path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/b15path.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_SS/ss_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_SS/ss_bc.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_SS/ss_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_SS/ss_n.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/BQpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/BQpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/b25path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/b25path.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/ss_bc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/ss_bc1.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/bpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/bpath.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/cpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/cpath.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/npath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/npath.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/ss_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/ss_bc.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_C.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_K.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_K.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_L.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_L.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_Y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_Y.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_r.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/tpi_w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/tpi_w.png -------------------------------------------------------------------------------- /Tutorials/DataFiles/out.csv: -------------------------------------------------------------------------------- 1 | ,something,a,b,c,d,message 2 | 0,one,1,2,3.0,4, 3 | 1,two,5,6,,8,world 4 | 2,three,9,10,11.0,12,foo 5 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/bpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/bpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/cpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/cpath.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/npath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/npath.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_C.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_K.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_K.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_L.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_L.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_Y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_Y.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_r.png -------------------------------------------------------------------------------- /Students/Fiona/PS5/images_TPI/tpi_w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS5/images_TPI/tpi_w.png -------------------------------------------------------------------------------- /Students/Fiona/PS3/images/C_aggr_path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS3/images/C_aggr_path.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/C_aggr_path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/C_aggr_path.png -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/distribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/distribution.png -------------------------------------------------------------------------------- /Students/Fiona/PS8/images_ss_tpi/ss_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS8/images_ss_tpi/ss_bc.png -------------------------------------------------------------------------------- /Tutorials/LaTeX/LaTeX_probset_template.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Tutorials/LaTeX/LaTeX_probset_template.pdf -------------------------------------------------------------------------------- /Students/Fiona/PS6/images/bq_pct_quantile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS6/images/bq_pct_quantile.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/imm_rate_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/imm_rate_20.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/imm_rate_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/imm_rate_80.png -------------------------------------------------------------------------------- /Students/Sophia/ps4/images/MU_c_stitched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps4/images/MU_c_stitched.png -------------------------------------------------------------------------------- /Students/Sophia/ps4/images/MU_n_stitched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps4/images/MU_n_stitched.png -------------------------------------------------------------------------------- /Students/Sophia/ps5/images/MU_c_stitched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps5/images/MU_c_stitched.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/fert_rate_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/fert_rate_100.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/fert_rate_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/fert_rate_20.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/fert_rate_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/fert_rate_80.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/imm_rate_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/imm_rate_100.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/mort_rate_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/mort_rate_100.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/mort_rate_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/mort_rate_20.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/mort_rate_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/mort_rate_80.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/population_dist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/population_dist.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/population_growth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/population_growth.png -------------------------------------------------------------------------------- /Students/Fiona/PS7/images_dem/population_dist_times.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Fiona/PS7/images_dem/population_dist_times.png -------------------------------------------------------------------------------- /Students/Sophia/ps4/images/Marginal_Disutility_ellip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rickecon/OGcourse_F17/HEAD/Students/Sophia/ps4/images/Marginal_Disutility_ellip.png -------------------------------------------------------------------------------- /Tutorials/DataFiles/csv_mindex.csv: -------------------------------------------------------------------------------- 1 | key1,key2,value1,value2 2 | one,a,1,2 3 | one,b,3,4 4 | one,c,5,6 5 | one,d,7,8 6 | two,a,9,10 7 | two,b,11,12 8 | two,c,13,14 9 | two,d,15,16 -------------------------------------------------------------------------------- /Students/Fiona/PS5/output_tpi.csv: -------------------------------------------------------------------------------- 1 | ,0 2 | b_last,0.22789371923062302 3 | b_err,0.5467916400621355 4 | n_err,8.432073393294104e-06 5 | cnt_err,2.669289264822794e-05 6 | T_1,20.0 7 | -------------------------------------------------------------------------------- /Tutorials/DataFiles/ex4.csv: -------------------------------------------------------------------------------- 1 | # hey! 2 | a,b,c,d,message 3 | # just wanted to make things more difficult for you 4 | # who reads CSV files with computers, anyway? 5 | 1,2,3,4,hello 6 | 5,6,7,8,world 7 | 9,10,11,12,foo -------------------------------------------------------------------------------- /Students/Fiona/PS6/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Students/Fiona/PS8/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Students/Fiona/PS8/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /Students/Fiona/PS8/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/output_ss.csv: -------------------------------------------------------------------------------- 1 | ,0 2 | r_ss,0.722701363735135 3 | w_ss,0.35804971875493546 4 | K_ss,1.7821040941837956 5 | L_ss,9.791038678849379 6 | Y_ss,5.393432798222523 7 | C_ss,4.793612971934751 8 | b_err,3.0984432640934756e-05 9 | n_err,5.950795411990839e-14 10 | b_last,7.597539953141386e-05 11 | cnt_err:,-1.1306057201565523e-09 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | build/* 3 | dist/* 4 | *.aux 5 | *.bbl 6 | *.blg 7 | *.fdb_latexmk 8 | *.idx 9 | *.ilg 10 | *.ind 11 | *.lof 12 | *.log 13 | *.lot 14 | *.out 15 | *.pdfsync 16 | *.synctex.gz 17 | *.toc 18 | *.swp 19 | *.asv 20 | *.nav 21 | *.snm 22 | *.gz 23 | *.bib.bak 24 | *.fls 25 | *.m~ 26 | *.sublime* 27 | .DS_Store 28 | *.dta 29 | *.ipynb_checkpoints* 30 | -------------------------------------------------------------------------------- /Students/Sophia/ps5/firms.py: -------------------------------------------------------------------------------- 1 | def get_w(r, params): # function for wage given interest rate 2 | A, alpha, delta = params 3 | w = (1 - alpha) * A * (((alpha * A) / (r + delta)) ** (alpha / (1 - alpha))) 4 | return w 5 | 6 | def get_r(K, L, params): # function for interest rate given aggregate capital and labor 7 | A, alpha, delta = params 8 | r = alpha * A * ((L / K) ** (1 - alpha)) - delta 9 | return r 10 | -------------------------------------------------------------------------------- /Students/Fiona/PS7/driver.py: -------------------------------------------------------------------------------- 1 | from PS7 import demographics as demog 2 | 3 | #population parameters 4 | E= 20 5 | S =80 6 | tot_per= E+S 7 | beg_yr_demog = 1 8 | end_yr_demog = 100 9 | fert_graph = True 10 | mort_graph = True 11 | imm_graph = True 12 | fert_rates = demog.get_fer(tot_per, beg_yr_demog, end_yr_demog, fert_graph) 13 | mort_rates = demog.ger_mort(tot_per, beg_yr_demog, end_yr_demog, mort_graph) 14 | imm_rates = demog.ger_imm_resid(tot_per, beg_yr_demog, end_yr_demog, imm_graph) 15 | 16 | -------------------------------------------------------------------------------- /Students/Fiona/PS8/.idea/PS7.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /Tutorials/DataFiles/geyser.csv: -------------------------------------------------------------------------------- 1 | 4.37 2 | 3.87 3 | 4 4 | 4.03 5 | 3.5 6 | 4.08 7 | 2.25 8 | 4.7 9 | 1.73 10 | 4.93 11 | 1.73 12 | 4.62 13 | 3.43 14 | 4.25 15 | 1.68 16 | 3.92 17 | 3.68 18 | 3.1 19 | 4.03 20 | 1.77 21 | 4.08 22 | 1.75 23 | 3.2 24 | 1.85 25 | 4.62 26 | 1.97 27 | 4.5 28 | 3.92 29 | 4.35 30 | 2.33 31 | 3.83 32 | 1.88 33 | 4.6 34 | 1.8 35 | 4.73 36 | 1.77 37 | 4.57 38 | 1.85 39 | 3.52 40 | 4 41 | 3.7 42 | 3.72 43 | 4.25 44 | 3.58 45 | 3.8 46 | 3.77 47 | 3.75 48 | 2.5 49 | 4.5 50 | 4.1 51 | 3.7 52 | 3.8 53 | 3.43 54 | 4 55 | 2.27 56 | 4.4 57 | 4.05 58 | 4.25 59 | 3.33 60 | 2 61 | 4.33 62 | 2.93 63 | 4.58 64 | 1.9 65 | 3.58 66 | 3.73 67 | 3.73 68 | 1.82 69 | 4.63 70 | 3.5 71 | 4 72 | 3.67 73 | 1.67 74 | 4.6 75 | 1.67 76 | 4 77 | 1.8 78 | 4.42 79 | 1.9 80 | 4.63 81 | 2.93 82 | 3.5 83 | 1.97 84 | 4.28 85 | 1.83 86 | 4.13 87 | 1.83 88 | 4.65 89 | 4.2 90 | 3.93 91 | 4.33 92 | 1.83 93 | 4.53 94 | 2.03 95 | 4.18 96 | 4.43 97 | 4.07 98 | 4.13 99 | 3.95 100 | 4.1 101 | 2.72 102 | 4.58 103 | 1.9 104 | 4.5 105 | 1.95 106 | 4.83 107 | 4.12 -------------------------------------------------------------------------------- /Tutorials/DataFiles/penny.csv: -------------------------------------------------------------------------------- 1 | U.S. penny thickness dataset,, 2 | "Source: Bradford S. Brown, Registered Professional Engineer, Houston Texas",, 3 | Thickness in mils of a smaple of 90 U.S. Lincoln pennies dated from 1945 to 1989.,, 4 | Two pennies were measured for each year. 1 mil = 0.001 inch.,, 5 | ,, 6 | year,penny1,penny2 7 | 1945,51.8,54.6 8 | 1946,53.2,54.2 9 | 1947,53,53 10 | 1948,53.6,52.2 11 | 1949,53.2,51.6 12 | 1950,53.4,51 13 | 1951,53.4,54 14 | 1952,53.4,54.6 15 | 1953,50.6,54.8 16 | 1954,52.2,54.6 17 | 1955,52.6,54.2 18 | 1956,54,53.6 19 | 1957,53.6,55 20 | 1958,53.2,53.2 21 | 1959,56.8,57.2 22 | 1960,57,55.2 23 | 1961,56.6,57 24 | 1962,54.6,56 25 | 1963,58,56.2 26 | 1964,55,56 27 | 1965,56.6,58.2 28 | 1966,57.2,56 29 | 1967,57.6,55.8 30 | 1968,57.2,56 31 | 1969,58,56 32 | 1970,57.2,55.6 33 | 1971,58,55.8 34 | 1972,57,57 35 | 1973,59,57.6 36 | 1974,59,54 37 | 1975,54,54.2 38 | 1976,53.2,53.2 39 | 1977,54,53.2 40 | 1978,53,53.6 41 | 1979,54,53 42 | 1980,53.6,53 43 | 1981,54.8,54 44 | 1982,54.4,54.6 45 | 1983,52.8,52.6 46 | 1984,55.2,54 47 | 1985,55.6,56 48 | 1986,55,53.2 49 | 1987,55,54 50 | 1988,54,55.6 51 | 1989,56.2,54 -------------------------------------------------------------------------------- /Students/Fiona/PS4/ellipse.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | 7 | def fit_ellip(elast_Frisch, l_tilde): 8 | b_i=0.1 9 | upsi_i=0.3 10 | l_sup=np.linspace(0.05,0.95, 1000) 11 | fargs=(elast_Frisch,l_tilde,l_sup) 12 | bnds=((1e-10, None), (1e-10, None)) 13 | params_init=np.array([b_i,upsi_i]) 14 | result=opt.minimize(MU_err,params_init,args=(fargs),bounds=bnds) 15 | b_ellip, upsilon=result.x 16 | sum_err=result.fun 17 | return b_ellip, upsilon 18 | 19 | 20 | def MU_err (params,*args): 21 | bi, ui = params 22 | theta, l_tilde, l_sup=args 23 | MU_cfe= l_sup**(1/theta) 24 | MU_elp=1/l_sup*bi*((l_sup/l_tilde)**ui)*(1-(l_sup/l_tilde)**ui)**(1/ui-1) 25 | sum_sqerr=((MU_cfe-MU_elp)**2).sum() 26 | return sum_sqerr 27 | 28 | theta=0.9 29 | l_tilde=1 30 | b,upsilon=fit_ellip(theta,l_tilde) 31 | l_sup=np.linspace(0.05,0.95, 1000) 32 | MU_cfe=l_sup**(1/theta) 33 | MU_elp=1/l_sup*b*((l_sup/l_tilde)**upsilon)*(1-(l_sup/l_tilde)**upsilon)**(1/upsilon-1) 34 | fig, ax = plt.subplots() 35 | plt.plot(l_sup, MU_elp, label='Ellipse MU') 36 | plt.plot(l_sup, MU_cfe, label='CFE MU') 37 | minorLocator = MultipleLocator(1) 38 | ax.xaxis.set_minor_locator(minorLocator) 39 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 40 | plt.title('CFE marginal utility versus fitted Ellipse', 41 | fontsize=20) 42 | plt.xlabel(r'Labor supply $n_{s,t}$') 43 | plt.ylabel(r'Marginal disutility') 44 | plt.xlim((0, 1)) 45 | plt.legend(loc='upper left') 46 | plt.savefig('EllipseVSCFE_MU') 47 | plt.show() 48 | plt.close() 49 | -------------------------------------------------------------------------------- /Students/Sophia/ps5/execute.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | import SS as ss 4 | import TPI as tpi 5 | import aggregates as aggr 6 | 7 | # Household Parameters 8 | yrs_live = 80 9 | S = 10 10 | beta_annual = .96 11 | beta = beta_annual ** (yrs_live / S) 12 | sigma = 2.2 13 | ltilde = 1.0 14 | b = 0.50 15 | upsilon = 1.5 16 | chi_n_vec = 1.0 * np.ones(S) 17 | 18 | # Firms Parameters 19 | alpha = 0.35 20 | A = 1.0 21 | delta_annual = 0.05 22 | delta = 1.0 - ((1.0 - delta_annual) ** (yrs_live / S)) 23 | 24 | # SS Parameters 25 | ss_solve = True 26 | ss_max_iter = 400 27 | ss_tol = 1e-13 28 | xi_ss = 0.1 29 | 30 | if ss_solve: 31 | c1_guess = 0.5 32 | r_old = 0.5 33 | params = (beta, sigma, S, ltilde, b, upsilon, chi_n_vec, A, alpha, delta, ss_max_iter, ss_tol, xi_ss) 34 | r_ss, w_ss, c_ss, n_ss, b_ss, K_ss, L_ss, C_ss, Y_ss, b_err, n_err, b_last = ss.get_SS(c1_guess, r_old, params) 35 | ss.create_graphs(c_ss, b_ss, n_ss) 36 | print(r_ss, w_ss, K_ss, L_ss, Y_ss, C_ss) 37 | print("savings euler error is {}".format(b_err)) 38 | print("labor supply euler error is {}".format(n_err)) 39 | print("final period saving is {}".format(b_last)) 40 | print("resource constraint error is {}".format(Y_ss - C_ss - delta * K_ss)) 41 | 42 | # TPI Patameters 43 | tpi_solve = True 44 | T1 = 60 45 | T2 = 90 46 | tpi_max_iter = 500 47 | tpi_tol = 1e-12 48 | xi_tpi = 0.3 49 | b1vec = 1.08 * b_ss 50 | 51 | if tpi_solve: 52 | ss_params = r_ss, w_ss, c_ss, n_ss, b_ss, K_ss, L_ss 53 | params = (beta, sigma, S, ltilde, b, upsilon, chi_n_vec, A, alpha, delta, tpi_max_iter, tpi_tol, xi_tpi, T1, T2) 54 | cmat, nmat, bmat, r, w, K, L, Y, C, b_err, n_err, b_last, Rc_err, T1 = tpi.get_TPI(b1vec, ss_params, params) 55 | tpi.create_graphs(r, w, K, L, Y, C, cmat, nmat, bmat, T2, S) 56 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/driver.py: -------------------------------------------------------------------------------- 1 | import SS as ss 2 | import TPI as tpi 3 | import utils 4 | import numpy as np 5 | 6 | # Household Parameters 7 | yrs_live = 80 8 | S = 10 9 | beta_annual = .96 10 | beta = beta_annual ** (yrs_live / S) 11 | sigma = 2.5 12 | l_ub = 1.0 13 | b = 0.5 14 | upsilon = 1.5 15 | chi=np.ones(S) 16 | 17 | # Firms Parameters 18 | alpha = 0.35 19 | A = 1.0 20 | delta_annual = 0.05 21 | delta = 1.0 - ((1.0 - delta_annual) ** (yrs_live / S)) 22 | 23 | 24 | # SS Parameters 25 | ss_solve = True 26 | ss_max_iter = 400 27 | ss_tol = 1e-9 28 | xi_ss = 0.1 29 | 30 | if ss_solve: 31 | c1_guess = 0.5 32 | r_old = 0.5 33 | params = (S, beta, S, sigma, l_ub, b, upsilon, chi, A, alpha, delta, ss_max_iter, ss_tol, xi_ss) 34 | r_ss, w_ss, c_ss, n_ss, b_ss, K_ss, L_ss,b_err, n_err, b_last = ss.get_SS(c1_guess, r_old, params) 35 | C_ss=utils.get_C(c_ss) 36 | Y_ss=utils.get_Y(K_ss,L_ss,(A, alpha)) 37 | cnt_err= Y_ss - C_ss - delta * K_ss 38 | # ss.create_graphs(c_ss, b_ss, n_ss) 39 | # ss.write_csv(r_ss, w_ss, K_ss, L_ss, Y_ss, C_ss,b_err, n_err, b_last, cnt_err) 40 | 41 | 42 | # TPI Patameters 43 | tpi_solve = True 44 | T1 = 60 45 | T2 = 90 46 | tpi_max_iter = 500 47 | tpi_tol = 1e-12 48 | xi_tpi = 0.3 49 | b1vec = 1.08 * b_ss 50 | 51 | if tpi_solve: 52 | c1_guess = 1 53 | ss_params = r_ss, w_ss, c_ss, n_ss, b_ss, K_ss, L_ss 54 | params = (beta, sigma, S, l_ub, b, upsilon, chi, A, alpha, delta, tpi_max_iter, tpi_tol, xi_tpi, T1, T2) 55 | r, w, K, L,bmat, nmat, cmat, b_last, b_err, n_err, cnt_err, T_1 = tpi.get_TPI(b1vec, c1_guess, ss_params, params) 56 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 57 | 58 | C = utils.get_C(cmat) 59 | 60 | tpi.create_graphs(T2, S, r, w, K, L, C, Y, bmat, cmat, nmat) 61 | tpi.write_csv(b_last, b_err, n_err, cnt_err,T_1) 62 | # T, S, rpath, wpath, Kpath, Lpath, Cpath, Ypath, bpath, cpath, npath 63 | -------------------------------------------------------------------------------- /Tutorials/DataFiles/Econ381totpts.txt: -------------------------------------------------------------------------------- 1 | 275.5 2 | 351.5 3 | 346.25 4 | 228.25 5 | 108.25 6 | 380.75 7 | 346.25 8 | 360.75 9 | 196 10 | 414.75 11 | 370.5 12 | 371.75 13 | 143.75 14 | 333.5 15 | 397.5 16 | 405.75 17 | 154.75 18 | 321 19 | 279 20 | 326.5 21 | 49.5 22 | 402.75 23 | 389.75 24 | 382.25 25 | 337.75 26 | 311 27 | 105.5 28 | 380.5 29 | 236 30 | 326.5 31 | 343.75 32 | 328.75 33 | 316.25 34 | 348.25 35 | 338.75 36 | 375.75 37 | 410 38 | 17 39 | 414.25 40 | 21.25 41 | 369.625 42 | 318.875 43 | 336.125 44 | 429.875 45 | 407.5 46 | 415.75 47 | 332.375 48 | 397 49 | 375.875 50 | 419.125 51 | 270.125 52 | 299.25 53 | 384.125 54 | 335 55 | 408.5 56 | 414.25 57 | 253.5 58 | 339.25 59 | 338.75 60 | 355.375 61 | 326.375 62 | 240.375 63 | 385 64 | 435 65 | 317.25 66 | 365.625 67 | 372.75 68 | 365.125 69 | 349.625 70 | 366.75 71 | 386.5 72 | 391.75 73 | 403 74 | 258.5 75 | 386 76 | 411 77 | 350.25 78 | 402.25 79 | 294.625 80 | 291.125 81 | 378.125 82 | 442.0 83 | 428.1 84 | 347.3 85 | 431.8 86 | 430.4 87 | 426.0 88 | 433.5 89 | 331.1 90 | 405.7 91 | 415.5 92 | 406.4 93 | 418.6 94 | 400.7 95 | 408.8 96 | 404.8 97 | 409.4 98 | 410.8 99 | 402.5 100 | 401.0 101 | 415.3 102 | 390.8 103 | 394.6 104 | 399.0 105 | 380.0 106 | 397.5 107 | 368.7 108 | 394.7 109 | 304.3 110 | 391.1 111 | 388.4 112 | 370.3 113 | 384.6 114 | 383.5 115 | 305.6 116 | 286.5 117 | 367.9 118 | 329.8 119 | 288.2 120 | 338.5 121 | 333.6 122 | 268.6 123 | 335.2 124 | 296.3 125 | 269.1 126 | 243.2 127 | 159.4 128 | 448.4 129 | 449.8 130 | 435.9 131 | 429.4 132 | 428.3 133 | 427.5 134 | 422.5 135 | 409.8 136 | 415.8 137 | 413.4 138 | 416.8 139 | 406.7 140 | 383.9 141 | 389.0 142 | 387.2 143 | 368.6 144 | 399.5 145 | 382.6 146 | 355.9 147 | 389.9 148 | 342.5 149 | 365.2 150 | 320.3 151 | 341.5 152 | 248.1 153 | 305.0 154 | 279.2 155 | 275.7 156 | 204.5 157 | 235.0 158 | 102.2 159 | 112.3 160 | 130.6 161 | 60.2 -------------------------------------------------------------------------------- /Students/Fiona/PS4/stitch.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def MU_c_stitch(cvec, sigma): 4 | epsilon = 1e-4 5 | c_cnstr = cvec < epsilon 6 | muc = cvec ** (-sigma) 7 | m1 = (-sigma) * epsilon ** (-sigma - 1) 8 | m2 = epsilon ** (-sigma) - m1 * epsilon 9 | muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 10 | 11 | return muc 12 | 13 | def MU_n_stitch(nvec, params): 14 | l_tilde, b, upsilon = params 15 | epsilon_lb = 1e-6 16 | epsilon_ub = l_tilde - epsilon_lb 17 | nl_cstr = nvec < epsilon_lb 18 | nu_cstr = nvec > epsilon_ub 19 | 20 | mun = ((b / l_tilde) * ((nvec / l_tilde) ** (upsilon - 1)) * (1 - ((nvec / l_tilde) ** upsilon)) **\ 21 | ((1 - upsilon) / upsilon)) 22 | m1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_lb ** (upsilon - 2)) * \ 23 | ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 24 | (1 + ((epsilon_lb / l_tilde) ** upsilon) * ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** (-1)))) 25 | m2 = ((b / l_tilde) * ((epsilon_lb / l_tilde) ** (upsilon - 1)) * \ 26 | ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (m1 * epsilon_lb)) 27 | q1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_ub ** (upsilon - 2)) * \ 28 | ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 29 | (1 + ((epsilon_ub / l_tilde) ** upsilon) * ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** (-1)))) 30 | q2 = ((b / l_tilde) * ((epsilon_ub / l_tilde) ** (upsilon - 1)) * \ 31 | ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (q1 * epsilon_ub)) 32 | mun[nl_cstr] = m1 * nvec[nl_cstr] + m2 33 | mun[nu_cstr] = q1 * nvec[nu_cstr] + q2 34 | return mun 35 | 36 | cvec=np.array([-0.01,-0.004, 0.5, 2.6]) 37 | sigma=2.2 38 | print (MU_c_stitch(cvec,sigma)) 39 | 40 | nvec=np.array([-0.013, -0.002, 0.42, 1.007, 1.011]) 41 | l_tilde=1 42 | b=0.5 43 | upsilon=1.5 44 | print (MU_n_stitch(nvec,(l_tilde,b,upsilon))) -------------------------------------------------------------------------------- /Students/Sophia/ps5/aggregates.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def get_L(narr): # function for aggregate labor supply 4 | epsilon = 0.01 5 | a = epsilon / np.exp(1) 6 | b = 1 / epsilon 7 | if narr.ndim == 1: # This is the steady-state case 8 | L = narr.sum() 9 | L_cstr = L < epsilon 10 | if L_cstr: 11 | print('get_L() warning: Distribution of savings and/or ' + 12 | 'parameters created L < epsilon') 13 | # Force K >= eps by stitching a * exp(b * K) for K < eps 14 | L = a * np.exp(b * L) 15 | 16 | elif narr.ndim == 2: # This is the time path case 17 | L = narr.sum(axis=0) 18 | L_cstr = L < epsilon 19 | if L.min() < epsilon: 20 | print('get_L() warning: Aggregate capital constraint is ' + 21 | 'violated (L < epsilon) for some period in time ' + 22 | 'path.') 23 | L[L_cstr] = a * np.exp(b * L[L_cstr]) 24 | return L, L_cstr 25 | 26 | def get_K(barr): # function for aggregate capital supply 27 | epsilon = 0.01 28 | a = epsilon / np.exp(1) 29 | b = 1 / epsilon 30 | if barr.ndim == 1: # This is the steady-state case 31 | K = barr.sum() 32 | K_cstr = K < epsilon 33 | if K_cstr: 34 | print('get_K() warning: Distribution of savings and/or ' + 35 | 'parameters created K < epsilon') 36 | # Force K >= eps by stitching a * exp(b * K) for K < eps 37 | K = a * np.exp(b * K) 38 | 39 | elif barr.ndim == 2: # This is the time path case 40 | K = barr.sum(axis=0) 41 | K_cstr = K < epsilon 42 | if K.min() < epsilon: 43 | print('get_K() warning: Aggregate capital constraint is ' + 44 | 'violated (K < epsilon) for some period in time ' + 45 | 'path.') 46 | K[K_cstr] = a * np.exp(b * K[K_cstr]) 47 | 48 | return K, K_cstr 49 | 50 | def get_Y(K, L, params): # function for aggregate output 51 | A, alpha = params 52 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 53 | return Y 54 | 55 | def get_C(carr): 56 | if carr.ndim == 1: 57 | C = carr.sum() 58 | elif carr.ndim == 2: 59 | C = carr.sum(axis=0) 60 | 61 | return C 62 | -------------------------------------------------------------------------------- /Students/Sophia/ps4/ellip_util.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | from matplotlib.patches import Ellipse 6 | import os 7 | 8 | def get_sumsq(ellip_params, *args): 9 | b, upsilon = ellip_params 10 | elast_Frisch, nvec, ltilde = args 11 | mu_cfe = nvec ** (1 / elast_Frisch) 12 | mu_ellip = ((b / ltilde) * ((nvec / ltilde) ** (upsilon - 1)) * ((1 - ((nvec / ltilde) ** upsilon)) ** \ 13 | ((1 - upsilon) / upsilon))) 14 | sumsq = ((mu_cfe - mu_ellip) ** 2).sum() 15 | 16 | return sumsq 17 | 18 | def fit_ellip(ellip_init, elast_Frisch, ltilde, graph = False): 19 | nvec = np.linspace(0.05, 0.95, 1000) 20 | args = (elast_Frisch, nvec, ltilde) 21 | bnds_elp = ((1e-12, None), (1 + 1e-12, None)) 22 | ellip_params = opt.minimize( 23 | get_sumsq, ellip_init, args=(args), method='L-BFGS-B', 24 | bounds = bnds_elp) 25 | if ellip_params.success: 26 | b_ellip, upsilon = ellip_params.x 27 | else: 28 | raise ValueError("Failed to minimize sum of squares") 29 | if graph: 30 | cur_path = os.path.split(os.path.abspath(__file__))[0] 31 | output_fldr = "images" 32 | output_dir = os.path.join(cur_path, output_fldr) 33 | if not os.access(output_dir, os.F_OK): 34 | os.makedirs(output_dir) 35 | 36 | # Plot steady-state consumption and savings distributions 37 | MU_ellip = \ 38 | ((b_ellip / ltilde) * 39 | ((nvec / ltilde) ** (upsilon - 1)) * 40 | ((1 - ((nvec / ltilde) ** upsilon)) ** 41 | ((1 - upsilon) / upsilon))) 42 | MU_CFE = nvec ** (1 / elast_Frisch) 43 | fig, ax = plt.subplots() 44 | plt.plot(nvec, MU_ellip, label='Elliptical') 45 | plt.plot(nvec, MU_CFE, label='CFE') 46 | # for the minor ticks, use no labels; default NullFormatter 47 | minorLocator = MultipleLocator(1) 48 | ax.xaxis.set_minor_locator(minorLocator) 49 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 50 | plt.title('CFE marginal utility and elliptical utility', 51 | fontsize=20) 52 | plt.xlabel(r'Labor supply $n_{s,t}$') 53 | plt.ylabel(r'Marginal disutility') 54 | plt.xlim((0, ltilde)) 55 | # plt.ylim((-1.0, 1.15 * (b_ss.max()))) 56 | plt.legend(loc='upper left') 57 | output_path = os.path.join(output_dir, 58 | 'Marginal_Disutility_ellip') 59 | plt.savefig(output_path) 60 | # plt.show() 61 | plt.close() 62 | 63 | return b_ellip, upsilon 64 | 65 | elast_Frisch = 0.9 66 | ltilde = 1.0 67 | 68 | print(fit_ellip((1, 1), elast_Frisch, ltilde, graph = True)) 69 | -------------------------------------------------------------------------------- /Students/Fiona/PS2/TPI.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET 2 4 | Solving TPI for 3-period model 5 | Author: Fiona Fan 6 | ''' 7 | import time 8 | import numpy as np 9 | import scipy.optimize as opt 10 | import SS as ss 11 | import matplotlib 12 | import matplotlib.pyplot as plt 13 | from matplotlib.ticker import MultipleLocator 14 | 15 | 16 | def getPath(x1,xT,T): 17 | return np.linspace(int(x1), int(xT), int(T)) 18 | 19 | 20 | def b3_error(b3, *args): 21 | 22 | nvec, beta, sigma, b2, w_path, r_path = args 23 | n2, n3 = nvec 24 | w1, w2 = w_path 25 | r1, r2 = r_path 26 | c2 = (1 + r1) * b2 + w1 * n2 - b3 27 | c3 = (1 + r2) * b3 + w2 * n3 28 | muc2, muc3 = ss.get_MUc(np.array([c2, c3]), sigma) 29 | error = muc2 - beta * (1 + r2) * muc3 30 | return error 31 | def zero_func(bvec,*args): 32 | nvec, beta, sigma, w_path, r_path = args 33 | b = np.append([0], bvec) 34 | b1 = np.append(bvec, [0]) 35 | cvec = (1 + np.append([0], r_path)) * b + w_path * nvec - b1 36 | 37 | muc = cvec ** (-sigma) 38 | errors = muc[:-1] - beta * (1 + r_path) * muc[1:] 39 | 40 | return errors 41 | 42 | 43 | # def get_cbepath(params,rpath,wpath): 44 | # T, beta, sigma, nvec, bvec1, b_ss, TPI_tol, EulDiff = params 45 | 46 | 47 | def get_TPI(params,bvec): 48 | start_time = time.clock() 49 | (T, beta, sigma, nvec, L, A, alpha, delta, b_ss, K_ss, 50 | maxiter_TPI, mindist_TPI, xi) = params 51 | 52 | abs2 = 1 53 | tpi_iter = 0 54 | L = ss.get_L(nvec) 55 | K1 = ss.get_K(bvec)[0] 56 | Kpath_old = np.zeros(T + 1) 57 | Kpath_old[:-1] = getPath(K1, K_ss, T) 58 | Kpath_old[-1] = K_ss 59 | 60 | while abs2 > mindist_TPI and tpi_iter < maxiter_TPI: 61 | tpi_iter += 1 62 | w_path = ss.get_w((A, alpha), Kpath_old, L) 63 | r_path = ss.get_r((A, alpha, delta), Kpath_old, L) 64 | b = np.zeros([2,T+1]) 65 | #print(bvec) 66 | b[:,0] = bvec 67 | 68 | b32 = opt.root(b3_error, b[1,0], args=(nvec[1:], beta, sigma, b[0, 0], w_path[:2], r_path[:2])) 69 | b[1, 1] = b32.x 70 | 71 | for t in range(T - 1): 72 | bvec_guess = np.array([b[0,t], b[1,t + 1]]) 73 | bt = opt.root(zero_func, bvec_guess, (nvec, beta, sigma, w_path[t: t + 3], r_path[t + 1: t + 3])) 74 | bgrid=np.eye(2,dtype=bool) 75 | b[:,t+1:t+3]=bgrid*bt.x+b[:,t+1:t+3] 76 | 77 | # Calculate the implied capital stock from conjecture and the error 78 | Kpath_new = b.sum(axis=0) 79 | abs2 = ((Kpath_old[:] - Kpath_new[:]) ** 2).sum() 80 | # Update guess 81 | Kpath_old = xi * Kpath_new + (1 - xi) * Kpath_old 82 | print('iteration:', tpi_iter, ' squared distance: ', abs2) 83 | 84 | tpi_time = time.clock() - start_time 85 | 86 | return Kpath_old, r_path, w_path -------------------------------------------------------------------------------- /Students/Fiona/PS6/problem2.csv: -------------------------------------------------------------------------------- 1 | # b_ss,c_ss,EulErr_ss,RCerr_ss,w_ss,r_ss,K_ss,Y_ss,C_ss,BQ_ss 2 | 0.04,1.35,8.40439E-14,-0.07,1.38,0.04,505.59,124.31,99.10,1.14 3 | 0.08,1.34,3.55271E-15,,,,,,, 4 | 0.12,1.34,-1.13243E-14,,,,,,, 5 | 0.17,1.34,-6.21725E-15,,,,,,, 6 | 0.23,1.34,-4.44089E-16,,,,,,, 7 | 0.33,1.33,-4.21885E-15,,,,,,, 8 | 0.40,1.33,4.99600E-15,,,,,,, 9 | 0.47,1.33,-2.22045E-16,,,,,,, 10 | 0.55,1.32,-7.43849E-15,,,,,,, 11 | 0.63,1.32,8.04912E-15,,,,,,, 12 | 0.72,1.32,8.88178E-16,,,,,,, 13 | 0.81,1.32,-2.22045E-16,,,,,,, 14 | 0.91,1.31,1.11022E-16,,,,,,, 15 | 1.02,1.31,-4.44089E-16,,,,,,, 16 | 1.14,1.31,-3.33067E-16,,,,,,, 17 | 1.26,1.30,-5.21805E-15,,,,,,, 18 | 1.39,1.30,6.99441E-15,,,,,,, 19 | 1.53,1.30,-1.44329E-15,,,,,,, 20 | 1.67,1.30,-5.55112E-16,,,,,,, 21 | 1.82,1.29,9.99201E-16,,,,,,, 22 | 2.00,1.29,-8.88178E-16,,,,,,, 23 | 2.17,1.29,8.88178E-16,,,,,,, 24 | 2.35,1.28,1.11022E-16,,,,,,, 25 | 2.54,1.28,-9.99201E-16,,,,,,, 26 | 2.73,1.28,8.88178E-16,,,,,,, 27 | 2.94,1.28,-2.22045E-16,,,,,,, 28 | 3.16,1.27,1.11022E-16,,,,,,, 29 | 3.44,1.27,1.11022E-16,,,,,,, 30 | 3.72,1.27,4.44089E-16,,,,,,, 31 | 3.98,1.27,-4.44089E-16,,,,,,, 32 | 4.31,1.26,2.22045E-16,,,,,,, 33 | 4.60,1.26,-4.44089E-16,,,,,,, 34 | 4.94,1.26,7.77156E-16,,,,,,, 35 | 5.27,1.25,-1.33227E-15,,,,,,, 36 | 5.62,1.25,1.33227E-15,,,,,,, 37 | 6.10,1.25,-1.77636E-15,,,,,,, 38 | 6.51,1.25,8.88178E-16,,,,,,, 39 | 7.12,1.24,-6.66134E-16,,,,,,, 40 | 7.56,1.24,1.11022E-16,,,,,,, 41 | 7.99,1.24,7.77156E-16,,,,,,, 42 | 8.44,1.24,5.55112E-16,,,,,,, 43 | 8.91,1.23,4.44089E-16,,,,,,, 44 | 9.48,1.23,-1.22125E-15,,,,,,, 45 | 10.00,1.23,-1.11022E-16,,,,,,, 46 | 10.52,1.23,1.11022E-15,,,,,,, 47 | 11.07,1.22,-1.11022E-15,,,,,,, 48 | 11.65,1.22,-4.88498E-14,,,,,,, 49 | 12.24,1.22,1.37779E-13,,,,,,, 50 | 12.85,1.21,-8.64864E-14,,,,,,, 51 | 13.49,1.21,-2.10942E-15,,,,,,, 52 | 14.28,1.21,-2.22045E-16,,,,,,, 53 | 14.97,1.21,4.96270E-14,,,,,,, 54 | 15.69,1.20,-6.80012E-13,,,,,,, 55 | 15.39,1.20,1.63236E-12,,,,,,, 56 | 15.02,1.20,-1.46450E-12,,,,,,, 57 | 14.65,1.20,4.61076E-13,,,,,,, 58 | 14.26,1.19,3.44169E-15,,,,,,, 59 | 13.86,1.19,-4.10783E-14,,,,,,, 60 | 13.45,1.19,9.02611E-14,,,,,,, 61 | 13.03,1.19,-9.83658E-14,,,,,,, 62 | 12.59,1.18,2.06057E-13,,,,,,, 63 | 12.14,1.18,-3.23186E-13,,,,,,, 64 | 11.68,1.18,2.60902E-14,,,,,,, 65 | 11.20,1.18,2.93876E-13,,,,,,, 66 | 10.71,1.17,-2.88658E-14,,,,,,, 67 | 10.20,1.17,-2.43805E-13,,,,,,, 68 | 9.68,1.17,-4.57412E-14,,,,,,, 69 | 9.14,1.17,1.83520E-13,,,,,,, 70 | 8.58,1.16,1.04583E-13,,,,,,, 71 | 8.00,1.16,-1.30340E-13,,,,,,, 72 | 7.41,1.16,-9.78106E-14,,,,,,, 73 | 6.80,1.16,1.49769E-13,,,,,,, 74 | 6.17,1.15,5.98410E-14,,,,,,, 75 | 5.52,1.15,-2.17715E-13,,,,,,, 76 | 4.84,1.15,3.94129E-14,,,,,,, 77 | 4.15,1.15,1.46438E-13,,,,,,, 78 | 3.43,1.14,-2.37588E-14,,,,,,, 79 | 2.69,1.14,-2.72005E-14,,,,,,, 80 | 1.93,1.14,-3.83027E-14,,,,,,, 81 | 1.14,1.14,-2.98650E-14,,,,,,, -------------------------------------------------------------------------------- /Tutorials/DataFiles/emat.csv: -------------------------------------------------------------------------------- 1 | 0.407,0.272,0.291,0.342,0.425,0.694,1.8 0.4,0.287,0.317,0.378,0.47,0.74,1.95 0.395,0.301,0.345,0.415,0.517,0.79,2.11 0.39,0.317,0.374,0.455,0.567,0.843,2.29 0.387,0.332,0.404,0.497,0.619,0.9,2.47 0.384,0.349,0.435,0.54,0.673,0.959,2.67 0.382,0.365,0.467,0.585,0.728,1.02,2.87 0.381,0.382,0.5,0.631,0.786,1.09,3.09 0.381,0.4,0.533,0.678,0.844,1.16,3.32 0.381,0.418,0.567,0.726,0.904,1.24,3.56 0.382,0.436,0.602,0.774,0.964,1.31,3.81 0.383,0.455,0.636,0.823,1.02,1.4,4.06 0.386,0.474,0.671,0.872,1.09,1.48,4.33 0.388,0.493,0.705,0.922,1.15,1.57,4.61 0.391,0.512,0.74,0.97,1.21,1.66,4.89 0.395,0.532,0.774,1.02,1.27,1.76,5.18 0.399,0.552,0.807,1.07,1.32,1.86,5.47 0.403,0.571,0.84,1.11,1.38,1.96,5.76 0.408,0.591,0.872,1.16,1.44,2.07,6.06 0.413,0.61,0.903,1.2,1.49,2.18,6.36 0.418,0.629,0.933,1.24,1.54,2.28,6.65 0.424,0.648,0.962,1.28,1.59,2.39,6.94 0.429,0.667,0.99,1.32,1.64,2.51,7.22 0.435,0.685,1.02,1.35,1.68,2.62,7.5 0.441,0.703,1.04,1.39,1.73,2.73,7.76 0.447,0.72,1.06,1.42,1.76,2.84,8.01 0.453,0.736,1.09,1.45,1.8,2.95,8.24 0.46,0.751,1.11,1.47,1.83,3.05,8.45 0.466,0.766,1.12,1.5,1.86,3.15,8.64 0.471,0.779,1.14,1.52,1.89,3.25,8.81 0.477,0.792,1.16,1.54,1.92,3.34,8.95 0.483,0.803,1.17,1.55,1.94,3.43,9.06 0.488,0.814,1.18,1.57,1.96,3.5,9.15 0.492,0.822,1.19,1.58,1.97,3.57,9.2 0.497,0.83,1.2,1.59,1.99,3.63,9.22 0.5,0.836,1.2,1.59,2,3.68,9.21 0.503,0.841,1.21,1.6,2.01,3.72,9.16 0.506,0.844,1.21,1.6,2.02,3.75,9.08 0.508,0.845,1.22,1.6,2.02,3.77,8.96 0.509,0.845,1.22,1.6,2.03,3.77,8.82 0.509,0.843,1.22,1.6,2.03,3.76,8.64 0.508,0.839,1.21,1.6,2.03,3.74,8.43 0.506,0.834,1.21,1.59,2.03,3.71,8.19 0.503,0.827,1.21,1.58,2.03,3.66,7.93 0.499,0.819,1.2,1.58,2.03,3.6,7.64 0.495,0.809,1.2,1.57,2.03,3.52,7.33 0.489,0.797,1.19,1.56,2.03,3.44,7.01 0.481,0.784,1.18,1.55,2.02,3.34,6.66 0.473,0.769,1.17,1.54,2.02,3.23,6.31 0.464,0.753,1.16,1.54,2.02,3.11,5.95 0.453,0.735,1.15,1.53,2.02,2.99,5.58 0.442,0.717,1.15,1.52,2.02,2.86,5.21 0.43,0.697,1.14,1.51,2.02,2.72,4.84 0.416,0.676,1.13,1.5,2.02,2.57,4.48 0.402,0.654,1.12,1.49,2.02,2.42,4.12 0.387,0.631,1.11,1.48,2.02,2.27,3.77 0.371,0.608,1.1,1.47,2.03,2.12,3.44 0.355,0.584,1.09,1.47,2.03,1.97,3.11 0.338,0.559,1.08,1.46,2.04,1.82,2.81 0.32,0.535,1.07,1.46,2.05,1.67,2.52 0.304,0.511,1.06,1.45,2.01,1.65,2.41 0.289,0.489,1.04,1.45,1.97,1.61,2.29 0.275,0.468,1.03,1.44,1.92,1.58,2.19 0.262,0.449,1.02,1.44,1.87,1.55,2.1 0.251,0.431,1,1.43,1.82,1.51,2.01 0.24,0.415,0.988,1.42,1.77,1.49,1.93 0.231,0.4,0.97,1.42,1.71,1.46,1.85 0.222,0.385,0.95,1.41,1.66,1.43,1.79 0.213,0.372,0.928,1.39,1.6,1.4,1.72 0.206,0.359,0.903,1.38,1.55,1.38,1.66 0.198,0.347,0.876,1.36,1.49,1.35,1.61 0.192,0.336,0.846,1.34,1.43,1.33,1.55 0.185,0.326,0.813,1.32,1.38,1.31,1.51 0.179,0.316,0.778,1.29,1.32,1.28,1.46 0.174,0.307,0.739,1.24,1.27,1.26,1.42 0.169,0.298,0.699,1.19,1.22,1.24,1.38 0.164,0.29,0.657,1.11,1.17,1.22,1.34 0.159,0.282,0.615,1.01,1.12,1.2,1.3 0.155,0.274,0.573,0.879,1.07,1.18,1.27 0.151,0.267,0.533,0.729,1.03,1.16,1.24 -------------------------------------------------------------------------------- /Students/Fiona/PS7/pop_data.csv: -------------------------------------------------------------------------------- 1 | Age,2012,2013 2 | 0,"3,941,616","3,941,783" 3 | 1,"3,976,214","3,955,942" 4 | 2,"3,978,498","3,989,135" 5 | 3,"3,981,693","3,989,538" 6 | 4,"4,111,675","3,991,690" 7 | 5,"4,131,791","4,121,797" 8 | 6,"4,097,799","4,142,191" 9 | 7,"4,084,995","4,108,053" 10 | 8,"4,093,004","4,095,205" 11 | 9,"4,062,932","4,103,335" 12 | 10,"4,045,479","4,073,258" 13 | 11,"4,145,265","4,055,918" 14 | 12,"4,207,149","4,155,875" 15 | 13,"4,135,987","4,217,964" 16 | 14,"4,134,705","4,147,439" 17 | 15,"4,142,975","4,147,445" 18 | 16,"4,172,554","4,158,116" 19 | 17,"4,263,848","4,191,188" 20 | 18,"4,352,653","4,285,609" 21 | 19,"4,421,656","4,376,606" 22 | 20,"4,542,548","4,445,721" 23 | 21,"4,626,290","4,568,663" 24 | 22,"4,623,188","4,655,731" 25 | 23,"4,443,361","4,652,806" 26 | 24,"4,343,710","4,472,517" 27 | 25,"4,273,646","4,372,201" 28 | 26,"4,297,300","4,300,520" 29 | 27,"4,337,931","4,322,247" 30 | 28,"4,204,965","4,360,245" 31 | 29,"4,277,121","4,224,985" 32 | 30,"4,282,114","4,294,831" 33 | 31,"4,240,574","4,297,330" 34 | 32,"4,330,923","4,254,331" 35 | 33,"4,064,979","4,342,738" 36 | 34,"3,987,742","4,075,159" 37 | 35,"3,950,737","3,996,723" 38 | 36,"3,836,764","3,957,642" 39 | 37,"3,959,886","3,842,679" 40 | 38,"3,839,142","3,964,301" 41 | 39,"3,902,730","3,842,425" 42 | 40,"4,084,121","3,904,767" 43 | 41,"4,324,708","4,084,927" 44 | 42,"4,383,990","4,323,573" 45 | 43,"4,158,329","4,380,926" 46 | 44,"4,075,784","4,154,727" 47 | 45,"4,083,792","4,070,408" 48 | 46,"4,164,419","4,076,903" 49 | 47,"4,420,484","4,156,273" 50 | 48,"4,508,027","4,409,800" 51 | 49,"4,509,243","4,494,922" 52 | 50,"4,504,988","4,494,482" 53 | 51,"4,566,011","4,489,236" 54 | 52,"4,609,720","4,547,907" 55 | 53,"4,459,493","4,589,261" 56 | 54,"4,437,914","4,438,340" 57 | 55,"4,393,712","4,415,162" 58 | 56,"4,240,749","4,369,543" 59 | 57,"4,208,604","4,215,577" 60 | 58,"4,040,906","4,181,408" 61 | 59,"3,891,835","4,012,740" 62 | 60,"3,746,038","3,862,796" 63 | 61,"3,635,651","3,715,993" 64 | 62,"3,554,229","3,603,520" 65 | 63,"3,452,640","3,519,231" 66 | 64,"3,426,414","3,420,461" 67 | 65,"3,579,451","3,391,067" 68 | 66,"2,641,363","3,534,440" 69 | 67,"2,606,850","2,604,610" 70 | 68,"2,546,704","2,569,911" 71 | 69,"2,614,073","2,508,689" 72 | 70,"2,281,868","2,569,502" 73 | 71,"2,088,118","2,238,499" 74 | 72,"1,979,577","2,044,846" 75 | 73,"1,867,432","1,934,570" 76 | 74,"1,792,678","1,820,632" 77 | 75,"1,657,349","1,743,415" 78 | 76,"1,587,795","1,607,329" 79 | 77,"1,527,275","1,534,778" 80 | 78,"1,377,032","1,471,162" 81 | 79,"1,337,088","1,321,197" 82 | 80,"1,282,492","1,277,377" 83 | 81,"1,227,499","1,219,160" 84 | 82,"1,183,022","1,160,321" 85 | 83,"1,073,424","1,111,120" 86 | 84,"1,011,038","1,000,660" 87 | 85,"928,644","934,503" 88 | 86,"832,007","850,340" 89 | 87,"756,204","753,974" 90 | 88,"664,051","677,766" 91 | 89,"568,886","587,609" 92 | 90,"488,313","496,558" 93 | 91,"407,324","419,645" 94 | 92,"323,374","344,621" 95 | 93,"240,643","268,598" 96 | 94,"194,107","196,402" 97 | 95,"140,971","155,062" 98 | 96,"105,712","110,012" 99 | 97,"77,427","80,822" 100 | 98,"54,757","57,740" 101 | 99,"36,951","39,790" 102 | ,, -------------------------------------------------------------------------------- /Students/Fiona/PS8/pop_data.csv: -------------------------------------------------------------------------------- 1 | Age,2012,2013 2 | 0,"3,941,616","3,941,783" 3 | 1,"3,976,214","3,955,942" 4 | 2,"3,978,498","3,989,135" 5 | 3,"3,981,693","3,989,538" 6 | 4,"4,111,675","3,991,690" 7 | 5,"4,131,791","4,121,797" 8 | 6,"4,097,799","4,142,191" 9 | 7,"4,084,995","4,108,053" 10 | 8,"4,093,004","4,095,205" 11 | 9,"4,062,932","4,103,335" 12 | 10,"4,045,479","4,073,258" 13 | 11,"4,145,265","4,055,918" 14 | 12,"4,207,149","4,155,875" 15 | 13,"4,135,987","4,217,964" 16 | 14,"4,134,705","4,147,439" 17 | 15,"4,142,975","4,147,445" 18 | 16,"4,172,554","4,158,116" 19 | 17,"4,263,848","4,191,188" 20 | 18,"4,352,653","4,285,609" 21 | 19,"4,421,656","4,376,606" 22 | 20,"4,542,548","4,445,721" 23 | 21,"4,626,290","4,568,663" 24 | 22,"4,623,188","4,655,731" 25 | 23,"4,443,361","4,652,806" 26 | 24,"4,343,710","4,472,517" 27 | 25,"4,273,646","4,372,201" 28 | 26,"4,297,300","4,300,520" 29 | 27,"4,337,931","4,322,247" 30 | 28,"4,204,965","4,360,245" 31 | 29,"4,277,121","4,224,985" 32 | 30,"4,282,114","4,294,831" 33 | 31,"4,240,574","4,297,330" 34 | 32,"4,330,923","4,254,331" 35 | 33,"4,064,979","4,342,738" 36 | 34,"3,987,742","4,075,159" 37 | 35,"3,950,737","3,996,723" 38 | 36,"3,836,764","3,957,642" 39 | 37,"3,959,886","3,842,679" 40 | 38,"3,839,142","3,964,301" 41 | 39,"3,902,730","3,842,425" 42 | 40,"4,084,121","3,904,767" 43 | 41,"4,324,708","4,084,927" 44 | 42,"4,383,990","4,323,573" 45 | 43,"4,158,329","4,380,926" 46 | 44,"4,075,784","4,154,727" 47 | 45,"4,083,792","4,070,408" 48 | 46,"4,164,419","4,076,903" 49 | 47,"4,420,484","4,156,273" 50 | 48,"4,508,027","4,409,800" 51 | 49,"4,509,243","4,494,922" 52 | 50,"4,504,988","4,494,482" 53 | 51,"4,566,011","4,489,236" 54 | 52,"4,609,720","4,547,907" 55 | 53,"4,459,493","4,589,261" 56 | 54,"4,437,914","4,438,340" 57 | 55,"4,393,712","4,415,162" 58 | 56,"4,240,749","4,369,543" 59 | 57,"4,208,604","4,215,577" 60 | 58,"4,040,906","4,181,408" 61 | 59,"3,891,835","4,012,740" 62 | 60,"3,746,038","3,862,796" 63 | 61,"3,635,651","3,715,993" 64 | 62,"3,554,229","3,603,520" 65 | 63,"3,452,640","3,519,231" 66 | 64,"3,426,414","3,420,461" 67 | 65,"3,579,451","3,391,067" 68 | 66,"2,641,363","3,534,440" 69 | 67,"2,606,850","2,604,610" 70 | 68,"2,546,704","2,569,911" 71 | 69,"2,614,073","2,508,689" 72 | 70,"2,281,868","2,569,502" 73 | 71,"2,088,118","2,238,499" 74 | 72,"1,979,577","2,044,846" 75 | 73,"1,867,432","1,934,570" 76 | 74,"1,792,678","1,820,632" 77 | 75,"1,657,349","1,743,415" 78 | 76,"1,587,795","1,607,329" 79 | 77,"1,527,275","1,534,778" 80 | 78,"1,377,032","1,471,162" 81 | 79,"1,337,088","1,321,197" 82 | 80,"1,282,492","1,277,377" 83 | 81,"1,227,499","1,219,160" 84 | 82,"1,183,022","1,160,321" 85 | 83,"1,073,424","1,111,120" 86 | 84,"1,011,038","1,000,660" 87 | 85,"928,644","934,503" 88 | 86,"832,007","850,340" 89 | 87,"756,204","753,974" 90 | 88,"664,051","677,766" 91 | 89,"568,886","587,609" 92 | 90,"488,313","496,558" 93 | 91,"407,324","419,645" 94 | 92,"323,374","344,621" 95 | 93,"240,643","268,598" 96 | 94,"194,107","196,402" 97 | 95,"140,971","155,062" 98 | 96,"105,712","110,012" 99 | 97,"77,427","80,822" 100 | 98,"54,757","57,740" 101 | 99,"36,951","39,790" 102 | ,, -------------------------------------------------------------------------------- /Students/Fiona/PS6/PS6_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | 63 | 64 | 65 | \begin{document} 66 | 67 | \begin{flushleft} 68 | \textbf{\large{Problem Set 6}} \\ 69 | MACS 40000, Dr. Evans \\ 70 | Fiona Fan 71 | \end{flushleft} 72 | 73 | \vspace{5mm} 74 | 75 | \noindent\textbf{Problem 11.1 (a)}\\ 76 | \includegraphics[scale=0.5]{images/distribution.png} 77 | 78 | 79 | \noindent\textbf{Problem 11.1 (b)}\\ 80 | \includegraphics[scale=0.5]{images/bq_pct_quantile.png} 81 | \\ 82 | \noindent\textbf{Problem 11.2 (a)}\\ 83 | Please see file $problem2.csv$. 84 | 85 | 86 | \noindent\textbf{Problem 11.2 (b)}\\ 87 | \includegraphics[scale=0.5]{images/ss_bc.png} 88 | 89 | \noindent\textbf{Problem 11.3 (a)}\\ 90 | \includegraphics[scale=0.5]{images/rpath.png} 91 | \includegraphics[scale=0.5]{images/wpath.png} 92 | \includegraphics[scale=0.5]{images/Kpath.png} 93 | \includegraphics[scale=0.5]{images/BQpath.png} 94 | 95 | 96 | \noindent\textbf{Problem 11.3 (b)}\\ 97 | \includegraphics[scale=0.5]{images/b25path.png} 98 | \\ 99 | \end{document} -------------------------------------------------------------------------------- /ProblemSets/PS7/pop_data.csv: -------------------------------------------------------------------------------- 1 | Age,2012,2013 2 | 0,"3,941,616","3,941,783" 3 | 1,"3,976,214","3,955,942" 4 | 2,"3,978,498","3,989,135" 5 | 3,"3,981,693","3,989,538" 6 | 4,"4,111,675","3,991,690" 7 | 5,"4,131,791","4,121,797" 8 | 6,"4,097,799","4,142,191" 9 | 7,"4,084,995","4,108,053" 10 | 8,"4,093,004","4,095,205" 11 | 9,"4,062,932","4,103,335" 12 | 10,"4,045,479","4,073,258" 13 | 11,"4,145,265","4,055,918" 14 | 12,"4,207,149","4,155,875" 15 | 13,"4,135,987","4,217,964" 16 | 14,"4,134,705","4,147,439" 17 | 15,"4,142,975","4,147,445" 18 | 16,"4,172,554","4,158,116" 19 | 17,"4,263,848","4,191,188" 20 | 18,"4,352,653","4,285,609" 21 | 19,"4,421,656","4,376,606" 22 | 20,"4,542,548","4,445,721" 23 | 21,"4,626,290","4,568,663" 24 | 22,"4,623,188","4,655,731" 25 | 23,"4,443,361","4,652,806" 26 | 24,"4,343,710","4,472,517" 27 | 25,"4,273,646","4,372,201" 28 | 26,"4,297,300","4,300,520" 29 | 27,"4,337,931","4,322,247" 30 | 28,"4,204,965","4,360,245" 31 | 29,"4,277,121","4,224,985" 32 | 30,"4,282,114","4,294,831" 33 | 31,"4,240,574","4,297,330" 34 | 32,"4,330,923","4,254,331" 35 | 33,"4,064,979","4,342,738" 36 | 34,"3,987,742","4,075,159" 37 | 35,"3,950,737","3,996,723" 38 | 36,"3,836,764","3,957,642" 39 | 37,"3,959,886","3,842,679" 40 | 38,"3,839,142","3,964,301" 41 | 39,"3,902,730","3,842,425" 42 | 40,"4,084,121","3,904,767" 43 | 41,"4,324,708","4,084,927" 44 | 42,"4,383,990","4,323,573" 45 | 43,"4,158,329","4,380,926" 46 | 44,"4,075,784","4,154,727" 47 | 45,"4,083,792","4,070,408" 48 | 46,"4,164,419","4,076,903" 49 | 47,"4,420,484","4,156,273" 50 | 48,"4,508,027","4,409,800" 51 | 49,"4,509,243","4,494,922" 52 | 50,"4,504,988","4,494,482" 53 | 51,"4,566,011","4,489,236" 54 | 52,"4,609,720","4,547,907" 55 | 53,"4,459,493","4,589,261" 56 | 54,"4,437,914","4,438,340" 57 | 55,"4,393,712","4,415,162" 58 | 56,"4,240,749","4,369,543" 59 | 57,"4,208,604","4,215,577" 60 | 58,"4,040,906","4,181,408" 61 | 59,"3,891,835","4,012,740" 62 | 60,"3,746,038","3,862,796" 63 | 61,"3,635,651","3,715,993" 64 | 62,"3,554,229","3,603,520" 65 | 63,"3,452,640","3,519,231" 66 | 64,"3,426,414","3,420,461" 67 | 65,"3,579,451","3,391,067" 68 | 66,"2,641,363","3,534,440" 69 | 67,"2,606,850","2,604,610" 70 | 68,"2,546,704","2,569,911" 71 | 69,"2,614,073","2,508,689" 72 | 70,"2,281,868","2,569,502" 73 | 71,"2,088,118","2,238,499" 74 | 72,"1,979,577","2,044,846" 75 | 73,"1,867,432","1,934,570" 76 | 74,"1,792,678","1,820,632" 77 | 75,"1,657,349","1,743,415" 78 | 76,"1,587,795","1,607,329" 79 | 77,"1,527,275","1,534,778" 80 | 78,"1,377,032","1,471,162" 81 | 79,"1,337,088","1,321,197" 82 | 80,"1,282,492","1,277,377" 83 | 81,"1,227,499","1,219,160" 84 | 82,"1,183,022","1,160,321" 85 | 83,"1,073,424","1,111,120" 86 | 84,"1,011,038","1,000,660" 87 | 85,"928,644","934,503" 88 | 86,"832,007","850,340" 89 | 87,"756,204","753,974" 90 | 88,"664,051","677,766" 91 | 89,"568,886","587,609" 92 | 90,"488,313","496,558" 93 | 91,"407,324","419,645" 94 | 92,"323,374","344,621" 95 | 93,"240,643","268,598" 96 | 94,"194,107","196,402" 97 | 95,"140,971","155,062" 98 | 96,"105,712","110,012" 99 | 97,"77,427","80,822" 100 | 98,"54,757","57,740" 101 | 99,"36,951","39,790" 102 | ,, -------------------------------------------------------------------------------- /Students/Sophia/ps8/pop_data.csv: -------------------------------------------------------------------------------- 1 | Age,2012,2013 2 | 0,"3,941,616","3,941,783" 3 | 1,"3,976,214","3,955,942" 4 | 2,"3,978,498","3,989,135" 5 | 3,"3,981,693","3,989,538" 6 | 4,"4,111,675","3,991,690" 7 | 5,"4,131,791","4,121,797" 8 | 6,"4,097,799","4,142,191" 9 | 7,"4,084,995","4,108,053" 10 | 8,"4,093,004","4,095,205" 11 | 9,"4,062,932","4,103,335" 12 | 10,"4,045,479","4,073,258" 13 | 11,"4,145,265","4,055,918" 14 | 12,"4,207,149","4,155,875" 15 | 13,"4,135,987","4,217,964" 16 | 14,"4,134,705","4,147,439" 17 | 15,"4,142,975","4,147,445" 18 | 16,"4,172,554","4,158,116" 19 | 17,"4,263,848","4,191,188" 20 | 18,"4,352,653","4,285,609" 21 | 19,"4,421,656","4,376,606" 22 | 20,"4,542,548","4,445,721" 23 | 21,"4,626,290","4,568,663" 24 | 22,"4,623,188","4,655,731" 25 | 23,"4,443,361","4,652,806" 26 | 24,"4,343,710","4,472,517" 27 | 25,"4,273,646","4,372,201" 28 | 26,"4,297,300","4,300,520" 29 | 27,"4,337,931","4,322,247" 30 | 28,"4,204,965","4,360,245" 31 | 29,"4,277,121","4,224,985" 32 | 30,"4,282,114","4,294,831" 33 | 31,"4,240,574","4,297,330" 34 | 32,"4,330,923","4,254,331" 35 | 33,"4,064,979","4,342,738" 36 | 34,"3,987,742","4,075,159" 37 | 35,"3,950,737","3,996,723" 38 | 36,"3,836,764","3,957,642" 39 | 37,"3,959,886","3,842,679" 40 | 38,"3,839,142","3,964,301" 41 | 39,"3,902,730","3,842,425" 42 | 40,"4,084,121","3,904,767" 43 | 41,"4,324,708","4,084,927" 44 | 42,"4,383,990","4,323,573" 45 | 43,"4,158,329","4,380,926" 46 | 44,"4,075,784","4,154,727" 47 | 45,"4,083,792","4,070,408" 48 | 46,"4,164,419","4,076,903" 49 | 47,"4,420,484","4,156,273" 50 | 48,"4,508,027","4,409,800" 51 | 49,"4,509,243","4,494,922" 52 | 50,"4,504,988","4,494,482" 53 | 51,"4,566,011","4,489,236" 54 | 52,"4,609,720","4,547,907" 55 | 53,"4,459,493","4,589,261" 56 | 54,"4,437,914","4,438,340" 57 | 55,"4,393,712","4,415,162" 58 | 56,"4,240,749","4,369,543" 59 | 57,"4,208,604","4,215,577" 60 | 58,"4,040,906","4,181,408" 61 | 59,"3,891,835","4,012,740" 62 | 60,"3,746,038","3,862,796" 63 | 61,"3,635,651","3,715,993" 64 | 62,"3,554,229","3,603,520" 65 | 63,"3,452,640","3,519,231" 66 | 64,"3,426,414","3,420,461" 67 | 65,"3,579,451","3,391,067" 68 | 66,"2,641,363","3,534,440" 69 | 67,"2,606,850","2,604,610" 70 | 68,"2,546,704","2,569,911" 71 | 69,"2,614,073","2,508,689" 72 | 70,"2,281,868","2,569,502" 73 | 71,"2,088,118","2,238,499" 74 | 72,"1,979,577","2,044,846" 75 | 73,"1,867,432","1,934,570" 76 | 74,"1,792,678","1,820,632" 77 | 75,"1,657,349","1,743,415" 78 | 76,"1,587,795","1,607,329" 79 | 77,"1,527,275","1,534,778" 80 | 78,"1,377,032","1,471,162" 81 | 79,"1,337,088","1,321,197" 82 | 80,"1,282,492","1,277,377" 83 | 81,"1,227,499","1,219,160" 84 | 82,"1,183,022","1,160,321" 85 | 83,"1,073,424","1,111,120" 86 | 84,"1,011,038","1,000,660" 87 | 85,"928,644","934,503" 88 | 86,"832,007","850,340" 89 | 87,"756,204","753,974" 90 | 88,"664,051","677,766" 91 | 89,"568,886","587,609" 92 | 90,"488,313","496,558" 93 | 91,"407,324","419,645" 94 | 92,"323,374","344,621" 95 | 93,"240,643","268,598" 96 | 94,"194,107","196,402" 97 | 95,"140,971","155,062" 98 | 96,"105,712","110,012" 99 | 97,"77,427","80,822" 100 | 98,"54,757","57,740" 101 | 99,"36,951","39,790" 102 | ,, -------------------------------------------------------------------------------- /Students/Sophia/ps5/SS.py: -------------------------------------------------------------------------------- 1 | import time 2 | import numpy as np 3 | import scipy.optimize as opt 4 | import matplotlib.pyplot as plt 5 | from matplotlib.ticker import MultipleLocator 6 | import os 7 | import Households as hh 8 | import firms 9 | import aggregates as aggr 10 | 11 | def get_SS(c1_guess, r_old, params): 12 | beta, sigma, p, ltilde, b, upsilon, chi_n_vec, A, alpha, delta, ss_max_iter, ss_tol, xi_ss = params 13 | abs_ss = 1 14 | ss_iter = 0 15 | while abs_ss > ss_tol and ss_iter < ss_max_iter: 16 | ss_iter += 1 17 | r_old = r_old * np.ones(p) 18 | w_old = firms.get_w(r_old, (A, alpha, delta)) * np.ones(p) 19 | # Calculate household decisions that make last-period savings zero 20 | c1_args = (r_old, w_old, beta, sigma, ltilde, b, upsilon, chi_n_vec, p, 0.0) 21 | result_c1 = opt.root(hh.get_b_last, c1_guess, args = (c1_args)) 22 | if result_c1.success: 23 | c1 = result_c1.x 24 | else: 25 | raise ValueError("failed to find an appropriate initial consumption") 26 | # Calculate aggregate supplies for capital and labor 27 | cvec = hh.get_c(c1, r_old, beta, sigma, p) 28 | nvec = hh.get_n(cvec, sigma, ltilde, b, upsilon, chi_n_vec, w_old, p) 29 | bvec = hh.get_b(cvec, nvec, r_old, w_old, p) 30 | K = aggr.get_K(bvec)[0] 31 | L = aggr.get_L(nvec)[0] 32 | C = aggr.get_C(cvec) 33 | Y = aggr.get_Y(K, L, (A, alpha)) 34 | b_err = abs(hh.get_b_errors(cvec, r_old[0], beta, sigma)).max() 35 | n_err = abs(hh.get_n_errors(nvec, cvec, sigma, ltilde, b, upsilon, chi_n_vec, w_old[0])).max() 36 | b_last = hh.get_b_last(cvec[0], r_old, w_old, beta, sigma, ltilde, b, upsilon, chi_n_vec, p, 0.0) 37 | r_new = firms.get_r(K, L, (A, alpha, delta)) 38 | # Check market clearing 39 | abs_ss = ((r_new - r_old) ** 2).max() 40 | # Update guess 41 | r_old = xi_ss * r_new + (1 - xi_ss) * r_old 42 | print('iteration:', ss_iter, ' squared distance: ', abs_ss) 43 | return r_old[0], w_old[0], cvec, nvec, bvec, K, L, C, Y, b_err, n_err, b_last 44 | 45 | def create_graphs(c_ss, b_ss, n_ss): 46 | cur_path = os.path.split(os.path.abspath(__file__))[0] 47 | output_fldr = "images" 48 | output_dir = os.path.join(cur_path, output_fldr) 49 | if not os.access(output_dir, os.F_OK): 50 | os.makedirs(output_dir) 51 | age = np.arange(1, c_ss.shape[0] + 1) 52 | plt.plot(age, b_ss, 'go--', color = 'green', label = 'savings') 53 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 54 | plt.plot (age, c_ss, 'go--', color = 'blue', label = 'consumption') 55 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 56 | plt.title('Steady-State distribution of Consumption and Savings', fontsize=10) 57 | plt.xlabel('age') 58 | plt.ylabel('units of consumption') 59 | plt.legend() 60 | output_path1 = os.path.join(output_dir, 'ss_bc') 61 | plt.savefig(output_path1) 62 | plt.close() 63 | 64 | plt.plot(age, n_ss, 'go--', label = 'labor supply') 65 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 66 | plt.title('Steady-State distribution of Labor Supply', fontsize=20) 67 | plt.xlabel('age') 68 | plt.ylabel('labor supply') 69 | plt.legend() 70 | output_path2 = os.path.join(output_dir, 'ss_n') 71 | plt.savefig(output_path2) 72 | plt.close() 73 | -------------------------------------------------------------------------------- /Students/Fiona/PS2/driver.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET2 Driver 4 | Author: Fiona Fan 5 | ''' 6 | import SS as ss 7 | import TPI as tpi 8 | import numpy as np 9 | import matplotlib.pyplot as plt 10 | from matplotlib.ticker import MultipleLocator 11 | 12 | 13 | #Household parameters 14 | beta_annual=0.96 15 | beta=beta_annual**20 16 | sigma=3 17 | nvec=np.array([1.0,1.0,0.2]) 18 | L=nvec.sum() 19 | 20 | #Firm parameters 21 | A=1.0 22 | alpha=0.35 23 | delta_annual=0.05 24 | delta=1-((1-delta_annual)**20) 25 | 26 | 27 | 28 | ''' 29 | Problem 1: Checking if feasible () works properly 30 | ''' 31 | 32 | b_guess_1=np.array([1.0,1.2]) 33 | b_guess_2=np.array([0.06,-0.001]) 34 | b_guess_3=np.array([0.1,0.1]) 35 | f_params=(nvec,A,alpha,delta) 36 | results1=np.array(ss.feasible(f_params,b_guess_1)) 37 | results2=np.array(ss.feasible(f_params,b_guess_2)) 38 | results3=np.array(ss.feasible(f_params,b_guess_3)) 39 | print (results1) 40 | print (results2) 41 | print (results3) 42 | 43 | ''' 44 | Problem 2: Solving steady state 45 | ''' 46 | # SS parameters 47 | SS_tol = 1e-13 48 | SS_graphs = False 49 | 50 | bvec_guess = np.array([0.1, 0.1]) 51 | f_params = (nvec, A, alpha, delta) 52 | b_cnstr, c_cnstr, K_cnstr = ss.feasible(f_params, bvec_guess) 53 | ss_params = (beta, sigma, nvec, L, A, alpha, delta, SS_tol) 54 | ss_output = ss.get_SS(ss_params, bvec_guess,SS_graphs) 55 | 56 | ss_params2 = (0.55, sigma, nvec, L, A, alpha, delta, SS_tol) 57 | ss_output2=ss.get_SS(ss_params2, bvec_guess,SS_graphs) 58 | 59 | 60 | 61 | b_ss = ss_output['b_ss'] 62 | K_ss = ss_output['K_ss'] 63 | w_ss = ss_output['w_ss'] 64 | r_ss = ss_output['r_ss'] 65 | c_ss = ss_output['c_ss'] 66 | 67 | 68 | 69 | ''' 70 | Problem 3: Solving TPI 71 | ''' 72 | # TPI params 73 | T = 30 74 | max_iter = 300 75 | mindist_TPI = 1e-9 76 | xi = 0.5 77 | b1vec = np.array([0.8 * b_ss[0], 1.1 * b_ss[1]]) 78 | TPI_graph=False 79 | 80 | Kpath, r_path, w_path=tpi.get_TPI((T, beta, sigma, nvec, L, A, alpha, delta, b_ss, K_ss, 81 | max_iter, mindist_TPI, xi),b1vec) 82 | 83 | if TPI_graph: 84 | plt.plot(1 + np.arange(T + 5), np.append(Kpath[:T-2], K_ss * np.ones(7)), 'go--') 85 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 86 | plt.title('Time path of aggregate capital', fontsize=20) 87 | plt.xlabel(r'$t$') 88 | plt.ylabel(r'$K$') 89 | plt.show() 90 | 91 | plt.plot(1 + np.arange(T + 5), np.append(w_path[:T-2], w_ss * np.ones(7)), 'go--') 92 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 93 | plt.title('Time path of wage', fontsize=20) 94 | plt.xlabel(r'$t$') 95 | plt.ylabel(r'$w$') 96 | plt.show() 97 | 98 | plt.plot(1 + np.arange(T + 5), np.append(r_path[:T-2], r_ss * np.ones(7)), 'go--') 99 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 100 | plt.title('Time path of interest rate', fontsize=20) 101 | plt.xlabel(r'$t$') 102 | plt.ylabel(r'$r$') 103 | plt.show() 104 | 105 | 106 | # weizhi=np.where( Kpath-K_ss < 0.00001 ) 107 | # k_first=np.zeros_like(Kpath) 108 | # k_first = [1 for k in Kpath if abs(k - K_ss) < 0.00001] 109 | # print(k_first) 110 | k_first = [k for k in Kpath if abs(k - K_ss) < 0.00001][0] 111 | print(k_first) 112 | T1 = np.where(Kpath == k_first)[0][0] 113 | print(T1+1) 114 | 115 | k_last = [k for k in Kpath[:-3] if abs(k- K_ss) > 0.00001][-1] 116 | print(k_last) 117 | T2 = np.where(Kpath == k_last)[0][0] 118 | print(T2+1) -------------------------------------------------------------------------------- /Students/Fiona/PS4/PS4_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \usepackage{booktabs} 19 | \lstset{frame=single, 20 | language=Python, 21 | showstringspaces=false, 22 | columns=flexible, 23 | basicstyle={\small\ttfamily}, 24 | numbers=none, 25 | breaklines=true, 26 | breakatwhitespace=true 27 | tabsize=3 28 | } 29 | \usepackage{amsmath} 30 | \usepackage{amssymb} 31 | \usepackage{amsthm} 32 | \usepackage{harvard} 33 | \usepackage{setspace} 34 | \usepackage{float,color} 35 | \usepackage[pdftex]{graphicx} 36 | \usepackage{hyperref} 37 | \usepackage{pgfplotstable} 38 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 39 | \theoremstyle{definition} 40 | \newtheorem{theorem}{Theorem} 41 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 42 | \newtheorem{algorithm}[theorem]{Algorithm} 43 | \newtheorem{axiom}[theorem]{Axiom} 44 | \newtheorem{case}[theorem]{Case} 45 | \newtheorem{claim}[theorem]{Claim} 46 | \newtheorem{conclusion}[theorem]{Conclusion} 47 | \newtheorem{condition}[theorem]{Condition} 48 | \newtheorem{conjecture}[theorem]{Conjecture} 49 | \newtheorem{corollary}[theorem]{Corollary} 50 | \newtheorem{criterion}[theorem]{Criterion} 51 | \newtheorem{definition}[theorem]{Definition} 52 | \newtheorem{derivation}{Derivation} % Number derivations on their own 53 | \newtheorem{example}[theorem]{Example} 54 | \newtheorem{exercise}[theorem]{Exercise} 55 | \newtheorem{lemma}[theorem]{Lemma} 56 | \newtheorem{notation}[theorem]{Notation} 57 | \newtheorem{problem}[theorem]{Problem} 58 | \newtheorem{proposition}{Proposition} % Number propositions on their own 59 | \newtheorem{remark}[theorem]{Remark} 60 | \newtheorem{solution}[theorem]{Solution} 61 | \newtheorem{summary}[theorem]{Summary} 62 | %\numberwithin{equation}{section} 63 | \bibliographystyle{aer} 64 | %\newcommand\ve{\varepsilon} 65 | %\newcommand\boldline{\arrayrulewidth{1pt}\hline} 66 | 67 | 68 | \begin{document} 69 | 70 | \begin{flushleft} 71 | \textbf{\large{Problem Set \#[4]}} \\ 72 | MACS 40000, Dr. Evans \\ 73 | Fiona Fan 74 | \end{flushleft} 75 | 76 | \vspace{5mm} 77 | 78 | \noindent\textbf{Problem 7.1} 79 | \\ \textbf{Part (i).} 80 | \begin{align} 81 | \frac{\partial g_{cfe}(n)}{\partial n}=n^{\frac{1}{\theta}}\\ 82 | \frac{\partial g_{elp}(n)}{\partial n}=\frac{b (\frac{n}{\tilde{l}})^\upsilon (1-(\frac{n}{\tilde{l}})^\upsilon)^{(\frac{1}{\upsilon}-1)}}{n} 83 | \end{align} 84 | 85 | \textbf{Part (ii).} Please see Fig \ref{Fig1} 86 | 87 | \noindent\textbf{Problem 7.2} 88 | \\ \textbf{Part (i).} $u'(c)$=[ 1.40829679e+11 5.75433098e+10 4.59479342e+00 1.22196463e-01] 89 | \\ \textbf{Part (ii).} $g'(n)$=[ -3.24975000e+00 -4.99750001e-01 3.60237454e-01 1.01976045e+05 90 | 1.60214791e+05] 91 | 92 | \begin{figure}[htb] 93 | \centering 94 | \captionsetup{width=4.0in} 95 | \caption{\textbf{Problem 7.1 Part (ii)}} 96 | \label{Fig1} 97 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{fig1.png}}} 98 | 99 | \end{figure} 100 | 101 | \end{document} 102 | 103 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/SS.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | import utils 7 | import pandas as pd 8 | 9 | 10 | 11 | def get_SS(c1_guess, r_old, params): 12 | S, beta, p, sigma, l_tilde, b, upsilon, chi, A, alpha, delta, ss_max_iter, ss_tol, xi_ss = params 13 | abs_ss = 1 14 | ss_iter = 0 15 | while abs_ss > ss_tol and ss_iter < ss_max_iter: 16 | ss_iter += 1 17 | r_old = r_old * np.ones(p) 18 | w_old = utils.get_w(r_old, (A, alpha, delta)) * np.ones(p) 19 | # Calculate household decisions that make last-period savings zero 20 | c1_args = (r_old, w_old, beta, sigma, l_tilde, b, upsilon, p, 0.0, chi) 21 | result_c1 = opt.root(utils.get_b_last, c1_guess, args=(c1_args)) 22 | if result_c1.success: 23 | c1 = result_c1.x 24 | else: 25 | raise ValueError("failed to find an appropriate initial consumption") 26 | # Calculate aggregate supplies for capital and labor 27 | cvec = utils.get_c(c1, r_old, beta, sigma, p) 28 | nvec = utils.get_n(cvec, sigma, l_tilde, b, upsilon, w_old, p, chi) 29 | bvec = utils.get_b(cvec, nvec, r_old, w_old, p) 30 | K = utils.get_K(bvec)[0] 31 | L = utils.get_L(nvec)[0] 32 | r_new = utils.get_r(K, L, (A, alpha, delta)) 33 | # Check market clearing 34 | abs_ss = ((r_new - r_old) ** 2).max() 35 | # Update guess 36 | r_old = xi_ss * r_new + (1 - xi_ss) * r_old 37 | print('iteration:', ss_iter, ' squared distance: ', abs_ss) 38 | 39 | b_err = abs(utils.get_b_errors(cvec, r_old[0], beta, sigma)).max() 40 | n_err = abs(utils.get_n_errors(nvec, cvec, sigma, l_tilde, b, upsilon, w_old[0],chi)).max() 41 | b_last = utils.get_b_last(cvec[0], r_old, w_old, beta, sigma, l_tilde, b, upsilon, p, 0.0,chi) 42 | return r_old[0], w_old[0], cvec, nvec, bvec, K, L, b_err, n_err,b_last 43 | 44 | def create_graphs(c_ss, b_ss, n_ss): 45 | cur_path = os.path.split(os.path.abspath(__file__))[0] 46 | output_fldr = "images_SS" 47 | output_dir = os.path.join(cur_path, output_fldr) 48 | if not os.access(output_dir, os.F_OK): 49 | os.makedirs(output_dir) 50 | 51 | plt.plot (np.arange(21, 80, 6), b_ss, 'go--', color = 'green', label = 'savings') 52 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 53 | plt.plot (np.arange(21, 80, 6), c_ss, 'go--', color = 'blue', label = 'consumption') 54 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 55 | plt.title('Steady-State distribution of Consumption and Savings', fontsize=10) 56 | plt.xlabel('age') 57 | plt.ylabel('units of consumption') 58 | plt.legend() 59 | output_path1 = os.path.join(output_dir, 'ss_bc') 60 | plt.savefig(output_path1) 61 | plt.close() 62 | 63 | plt.plot (np.arange(21, 80, 6), n_ss, 'go--', label = 'labor supply') 64 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 65 | plt.title('Steady-State distribution of Labor Supply', fontsize=20) 66 | plt.xlabel('age') 67 | plt.ylabel('labor supply') 68 | plt.legend() 69 | output_path2 = os.path.join(output_dir, 'ss_n') 70 | plt.savefig(output_path2) 71 | plt.close() 72 | 73 | def write_csv(r_ss, w_ss, K_ss, L_ss, Y_ss, C_ss, b_err, n_err, b_last, cnt_err): 74 | output={'r_ss':r_ss, 'w_ss':w_ss, 'K_ss':K_ss, 'L_ss':L_ss, 'Y_ss':Y_ss, 'C_ss':C_ss, 'b_err':b_err, 'n_err':n_err, 75 | 'b_last':b_last, 'cnt_err:':cnt_err} 76 | pd.DataFrame.from_dict(data=output, orient='index').to_csv('output_ss.csv', header=True) -------------------------------------------------------------------------------- /Students/Sophia/ps4/ps4_writeup.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | \newcommand\ve{\varepsilon} 63 | \newcommand\boldline{\arrayrulewidth{1pt}\hline} 64 | 65 | 66 | \begin{document} 67 | 68 | \begin{flushleft} 69 | \textbf{\large{Problem Set 4}} \\ 70 | MACS 40000, Dr. Evans \\ 71 | Sophia Mo 72 | \end{flushleft} 73 | 74 | \vspace{5mm} 75 | 76 | \noindent\textbf{Problem 1(i)}\\ 77 | $\frac{\partial g_{cfe}(n)}{\partial n} = n^{\frac{1}{\sigma}}$\\ 78 | \\ 79 | $\frac{\partial g_{elp}(n)}{\partial n} = \frac{b}{\tilde{l}}(\frac{n}{\tilde{l}})^{\upsilon - 1}(1 - (\frac{n}{\tilde{l}})^\upsilon)^{\frac{1-\upsilon}{\upsilon}}$\\ 80 | \\ 81 | \noindent\textbf{Problem 1(ii)}\\ 82 | The estimated b is 0.5267708068873399, and upsilon is 1.4968180152979402.\\ 83 | \begin{center} 84 | \includegraphics[scale=0.5]{Marginal_Disutility_ellip} 85 | \end{center} 86 | \\ 87 | \noindent\textbf{Problem 2(i)}\\ 88 | The marginal utility values obstained from the stitched function are:\\ 89 | 1.40829679e+11, 5.75433098e+10, 4.59479342e+00, 1.22196463e-01\\ 90 | \begin{center} 91 | \includegraphics[scale=0.5]{MU_c_stitched} 92 | \end{center} 93 | \noindent\textbf{Problem 2(ii)}\\ 94 | The marginal disutility values are:\\ 95 | -3.24975000e+00, -4.99750001e-01, 3.60237454e-01, 1.01976045e+05, 96 | 1.60214791e+05\\ 97 | \begin{center} 98 | \includegraphics[scale=0.5]{MU_n_stitched} 99 | \end{center} 100 | \end{document} 101 | -------------------------------------------------------------------------------- /Students/Fiona/PS2/problem1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET2 problem1 4 | Author: Fiona Fan 5 | ''' 6 | import numpy as np 7 | import time 8 | import scipy.optimize as opt 9 | 10 | #Household parameters 11 | S= int(3) 12 | beta_annual=0.96 13 | beta=beta_annual**20 14 | sigma=2.2 15 | nvec=np.array([1.0,1.0,0.2]) 16 | L=nvec.sum() 17 | #Firm parameters 18 | A=1.0 19 | alpha=0.35 20 | delta_annual=0.05 21 | delta=1-((1-delta_annual)**20) 22 | 23 | def feasible(f_params, bvec_guess): 24 | b_cnstr=np.array([False,False]) 25 | nvec, A, alpha, delta=f_params 26 | #n1,n2,n3=nvec 27 | K,K_cnstr=get_K(bvec_guess) 28 | L=get_L(nvec) 29 | r=get_r(np.array([A, alpha, delta]),L,K) 30 | w=get_w(np.array([A, alpha]),L,K) 31 | c_vec,c_cnstr=get_cvec(r,w,bvec_guess,nvec) 32 | 33 | if c_cnstr[0]: 34 | b_cnstr[0]=True 35 | if c_cnstr[1]: 36 | b_cnstr[0]=True 37 | b_cnstr[1]=True 38 | if c_cnstr[2]: 39 | b_cnstr[1]=True 40 | return b_cnstr, c_cnstr, K_cnstr 41 | 42 | def get_r(params,L,K): 43 | A, alpha, delta=params 44 | return alpha*A*(L/K)**(1-alpha)-delta 45 | def get_w(params,L, K): 46 | A, alpha = params 47 | return (1-alpha)*A*(K/L)**alpha 48 | def get_cvec(r, w, bvec, nvec): 49 | b2,b3=bvec 50 | n1,n2,n3=nvec 51 | 52 | c1=w*n1-b2 53 | c2=w*n2+b2*(1+r)-b3 54 | c3=w*n3+b3*(1+r) 55 | c_vec=np.array([c1,c2,c3]) 56 | 57 | c_cnstr=(c_vec<=0) 58 | 59 | return c_vec, c_cnstr 60 | 61 | 62 | def get_K(b_vec): 63 | return sum(b_vec), sum(b_vec)<=0 64 | def get_L(nvec): 65 | return sum(nvec) 66 | def get_SS(params, bvec_guess, SS_graphs): 67 | start_time = time.clock() 68 | beta, sigma, nvec, L, A, alpha, delta, SS_tol = params 69 | f_params = (nvec, A, alpha, delta) 70 | b1_cnstr, c1_cnstr, K1_cnstr = feasible(f_params, bvec_guess) 71 | try: 72 | if b1_cnstr.max() or c1_cnstr.max() or K1_cnstr.max(): 73 | raise cstError 74 | break 75 | except cstError: 76 | pass 77 | 78 | 79 | 80 | ss_time = time.clock() - start_time 81 | ss_output={'b_ss': b_ss, 'c_ss': c_ss, 'w_ss': w_ss, 'r_ss': r_ss, 82 | 'K_ss': K_ss, 'Y_ss': Y_ss, 'C_ss': C_ss, 83 | 'EulErr_ss': EulErr_ss, 'RCerr_ss': RCerr_ss, 84 | 'ss_time': ss_time} 85 | 86 | return ss_output 87 | 88 | def EulerSys(bvec, params): 89 | 90 | beta, sigma, nvec, L, A, alpha, delta = params 91 | K, K_cnstr = get_K(bvec) 92 | try: 93 | if K_cnstr: 94 | raise cstError 95 | break 96 | 97 | else: 98 | r_params =np.array( (A, alpha, delta)) 99 | r = get_r(r_params, K, L) 100 | w_params = np.array((A, alpha)) 101 | w = get_w(w_params, K, L) 102 | cvec, c_cnstr = get_cvec(r, w, bvec, nvec) 103 | b_err_params = (beta, sigma) 104 | b_err_vec = get_b_errors(b_err_params, r, cvec, c_cnstr) 105 | except cstError: 106 | pass 107 | 108 | return b_err_vec 109 | 110 | def get_b_errors(params, r, cvec, c_cnstr): 111 | beta, sigma = params 112 | try: 113 | if c_cnstr.max(): 114 | raise cstError 115 | break 116 | 117 | return b_errors 118 | 119 | class cstError (Exception): 120 | print 'Did not pass the feasible test' 121 | #testing 122 | b2=0.06 123 | b3=-0.001 124 | b_guess=np.array([b2,b3]) 125 | f_params=(nvec,A,alpha,delta) 126 | b_cnstr, c_cnstr,K_cnstr=feasible(f_params,b_guess) 127 | print b_cnstr 128 | print c_cnstr 129 | print K_cnstr -------------------------------------------------------------------------------- /Students/Fiona/PS7/PS7_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | 63 | 64 | 65 | \begin{document} 66 | 67 | \begin{flushleft} 68 | \textbf{\large{Problem Set 7 }} \\ 69 | MACS 40000, Dr. Evans \\ 70 | Fiona Fan 71 | \end{flushleft} 72 | 73 | \vspace{5mm} 74 | 75 | \noindent\textbf{Problem 1 (a)}\\ 76 | \includegraphics[scale=0.5]{images_dem/fert_rate_100.png} 77 | 78 | 79 | \noindent\textbf{Problem 1 (b)}\\ 80 | \includegraphics[scale=0.5]{images_dem/fert_rate_80.png} 81 | \\ 82 | 83 | \noindent\textbf{Problem 1 (c)}\\ 84 | \includegraphics[scale=0.5]{images_dem/fert_rate_20.png} 85 | \\ 86 | 87 | \noindent\textbf{Problem 2 (a)}\\ 88 | \includegraphics[scale=0.5]{images_dem/mort_rate_100.png} 89 | \\ 90 | 91 | \noindent\textbf{Problem 2 (b)}\\ 92 | \includegraphics[scale=0.5]{images_dem/mort_rate_80.png} 93 | \\ 94 | 95 | \noindent\textbf{Problem 2 (c)}\\ 96 | \includegraphics[scale=0.5]{images_dem/mort_rate_20.png} 97 | \\ 98 | 99 | 100 | \noindent\textbf{Problem 3 (a)}\\ 101 | \includegraphics[scale=0.5]{images_dem/imm_rate_100.png} 102 | \\ 103 | 104 | \noindent\textbf{Problem 3 (b)}\\ 105 | \includegraphics[scale=0.5]{images_dem/imm_rate_80.png} 106 | \\ 107 | 108 | \noindent\textbf{Problem 3 (c)}\\ 109 | \includegraphics[scale=0.5]{images_dem/imm_rate_20.png} 110 | \\ 111 | \noindent\textbf{Problem 4 (a)}\\ 112 | \includegraphics[scale=0.5]{images_dem/population_dist.png} 113 | \\ 114 | 115 | \noindent\textbf{Problem 4 (b)}\\ 116 | \includegraphics[scale=0.5]{images_dem/population_dist_times.png} 117 | \\ 118 | 119 | \noindent\textbf{Problem 4 (c)}\\ 120 | \includegraphics[scale=0.5]{images_dem/population_growth.png} 121 | \\ 122 | 123 | \end{document} -------------------------------------------------------------------------------- /Students/Sophia/ps5/ps5_writeup.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | 63 | 64 | 65 | \begin{document} 66 | 67 | \begin{flushleft} 68 | \textbf{\large{Problem Set 4}} \\ 69 | MACS 40000, Dr. Evans \\ 70 | Sophia Mo 71 | \end{flushleft} 72 | 73 | \vspace{5mm} 74 | 75 | \noindent\textbf{Problem 1(a)}\\ 76 | \includegraphics[scale=0.5]{ss_bc.png} 77 | \includegraphics[scale=0.5]{ss_n}\\ 78 | \\ 79 | \noindent\textbf{Problem 1(b)}\\ 80 | \begin{table}[htbp!]\centering 81 | \begin{tabular}{|l|c|}\hline 82 | $\bar{r}$ & 0.67\\ 83 | $\bar{w}$ & 0.37\\ 84 | $\bar{K}$ & 1.90\\ 85 | $\bar{L}$ &9.70\\ 86 | $\bar{Y}$ &5.48\\ 87 | $\bar{C}$ &4.84\\ 88 | Savings Euler Error & $3.55e^{-15}$\\ 89 | Labor Euler Error & $3.19e^{-13}$\\ 90 | Last period saving & $-1.29e^{-13}$\\ 91 | Resource Constraint Error & $-2.01e^{-13}$\\ \hline 92 | \end{tabular} 93 | \end{table} 94 | \\ 95 | \noindent\textbf{Problem 2(a)}\\ 96 | \includegraphics[scale=0.35]{cpath} 97 | \includegraphics[scale=0.35]{npath} 98 | \includegraphics[scale=0.35]{bpath} 99 | \\ 100 | \noindent\textbf{Problem 2(b)}\\ 101 | \includegraphics[scale=0.35]{tpi_r} 102 | \includegraphics[scale=0.35]{tpi_w} 103 | \includegraphics[scale=0.35]{tpi_K} 104 | \includegraphics[scale=0.35]{tpi_L} 105 | \includegraphics[scale=0.35]{tpi_Y} 106 | \includegraphics[scale=0.35]{tpi_C} 107 | \\ 108 | \noindent\textbf{Problem 2(c)}\\ 109 | \begin{table}[htbp!]\centering 110 | \begin{tabular}{|l|c|}\hline 111 | Savings Euler Error & $0.37$\\ 112 | Labor Euler Error & $5.37e^{-8}$\\ 113 | Last period saving & $0.24$\\ 114 | Resource Constraint Error & $2.85e^{-7}$\\ \hline 115 | \end{tabular} 116 | \end{table} 117 | 118 | \noindent\textbf{Problem 2(d)}\\ 119 | It takes 21 periods for the ec onomy to get within 0.0001 of the steady-state aggregate capital stock. 120 | \end{document} 121 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/PS5_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | 63 | 64 | 65 | \begin{document} 66 | 67 | \begin{flushleft} 68 | \textbf{\large{Problem Set 5}} \\ 69 | MACS 40000, Dr. Evans \\ 70 | Fiona Fan 71 | \end{flushleft} 72 | 73 | \vspace{5mm} 74 | 75 | \noindent\textbf{Problem 7.3 (a)}\\ 76 | \includegraphics[scale=0.5]{images_SS/ss_bc.png} 77 | \includegraphics[scale=0.5]{images_SS/ss_n}\\ 78 | \\ 79 | \noindent\textbf{Problem 7.3 (b)}\\ 80 | \begin{table}[htbp!]\centering 81 | \begin{tabular}{|l|c|}\hline 82 | $\bar{r}$ & 0.72\\ 83 | $\bar{w}$ & 0.36\\ 84 | $\bar{K}$ & 1.78\\ 85 | $\bar{L}$ &9.79\\ 86 | $\bar{Y}$ &5.39\\ 87 | $\bar{C}$ &4.79\\ 88 | Savings Euler Error & $3.1e^{-5}$\\ 89 | Labor Euler Error & $5.95e^{-14}$\\ 90 | Last period saving & $7.6e^{-5}$\\ 91 | Resource Constraint Error & $-1.13e^{-9}$\\ \hline 92 | \end{tabular} 93 | \end{table} 94 | \\ 95 | \noindent\textbf{Problem 2(a)}\\ 96 | \includegraphics[scale=0.35]{images_TPI/cpath} 97 | \includegraphics[scale=0.35]{images_TPI/npath} 98 | \includegraphics[scale=0.35]{images_TPI/bpath} 99 | \\ 100 | \noindent\textbf{Problem 2(b)}\\ 101 | \includegraphics[scale=0.35]{images_TPI/tpi_r} 102 | \includegraphics[scale=0.35]{images_TPI/tpi_w} 103 | \includegraphics[scale=0.35]{images_TPI/tpi_K} 104 | \includegraphics[scale=0.35]{images_TPI/tpi_L} 105 | \includegraphics[scale=0.35]{images_TPI/tpi_Y} 106 | \includegraphics[scale=0.35]{images_TPI/tpi_C} 107 | \\ 108 | \noindent\textbf{Problem 2(c)}\\ 109 | \begin{table}[htbp!]\centering 110 | \begin{tabular}{|l|c|}\hline 111 | Savings Euler Error & $0.55$\\ 112 | Labor Euler Error & $8.43e^{-6}$\\ 113 | Last period saving & $0.23$\\ 114 | Resource Constraint Error & $2.67e^{-5}$\\ \hline 115 | \end{tabular} 116 | \end{table} 117 | 118 | \noindent\textbf{Problem 2(d)}\\ 119 | $T$ is 20 for the economy to get 0.0001 within $\bar{K}$. 120 | \end{document} -------------------------------------------------------------------------------- /Tutorials/DataFiles/iris.csv: -------------------------------------------------------------------------------- 1 | sepal_length,sepal_width,petal_length,petal_width,species 2 | 5.1,3.5,1.4,0.2,setosa 3 | 4.9,3,1.4,0.2,setosa 4 | 4.7,3.2,1.3,0.2,setosa 5 | 4.6,3.1,1.5,0.2,setosa 6 | 5,3.6,1.4,0.2,setosa 7 | 5.4,3.9,1.7,0.4,setosa 8 | 4.6,3.4,1.4,0.3,setosa 9 | 5,3.4,1.5,0.2,setosa 10 | 4.4,2.9,1.4,0.2,setosa 11 | 4.9,3.1,1.5,0.1,setosa 12 | 5.4,3.7,1.5,0.2,setosa 13 | 4.8,3.4,1.6,0.2,setosa 14 | 4.8,3,1.4,0.1,setosa 15 | 4.3,3,1.1,0.1,setosa 16 | 5.8,4,1.2,0.2,setosa 17 | 5.7,4.4,1.5,0.4,setosa 18 | 5.4,3.9,1.3,0.4,setosa 19 | 5.1,3.5,1.4,0.3,setosa 20 | 5.7,3.8,1.7,0.3,setosa 21 | 5.1,3.8,1.5,0.3,setosa 22 | 5.4,3.4,1.7,0.2,setosa 23 | 5.1,3.7,1.5,0.4,setosa 24 | 4.6,3.6,1,0.2,setosa 25 | 5.1,3.3,1.7,0.5,setosa 26 | 4.8,3.4,1.9,0.2,setosa 27 | 5,3,1.6,0.2,setosa 28 | 5,3.4,1.6,0.4,setosa 29 | 5.2,3.5,1.5,0.2,setosa 30 | 5.2,3.4,1.4,0.2,setosa 31 | 4.7,3.2,1.6,0.2,setosa 32 | 4.8,3.1,1.6,0.2,setosa 33 | 5.4,3.4,1.5,0.4,setosa 34 | 5.2,4.1,1.5,0.1,setosa 35 | 5.5,4.2,1.4,0.2,setosa 36 | 4.9,3.1,1.5,0.1,setosa 37 | 5,3.2,1.2,0.2,setosa 38 | 5.5,3.5,1.3,0.2,setosa 39 | 4.9,3.1,1.5,0.1,setosa 40 | 4.4,3,1.3,0.2,setosa 41 | 5.1,3.4,1.5,0.2,setosa 42 | 5,3.5,1.3,0.3,setosa 43 | 4.5,2.3,1.3,0.3,setosa 44 | 4.4,3.2,1.3,0.2,setosa 45 | 5,3.5,1.6,0.6,setosa 46 | 5.1,3.8,1.9,0.4,setosa 47 | 4.8,3,1.4,0.3,setosa 48 | 5.1,3.8,1.6,0.2,setosa 49 | 4.6,3.2,1.4,0.2,setosa 50 | 5.3,3.7,1.5,0.2,setosa 51 | 5,3.3,1.4,0.2,setosa 52 | 7,3.2,4.7,1.4,versicolor 53 | 6.4,3.2,4.5,1.5,versicolor 54 | 6.9,3.1,4.9,1.5,versicolor 55 | 5.5,2.3,4,1.3,versicolor 56 | 6.5,2.8,4.6,1.5,versicolor 57 | 5.7,2.8,4.5,1.3,versicolor 58 | 6.3,3.3,4.7,1.6,versicolor 59 | 4.9,2.4,3.3,1,versicolor 60 | 6.6,2.9,4.6,1.3,versicolor 61 | 5.2,2.7,3.9,1.4,versicolor 62 | 5,2,3.5,1,versicolor 63 | 5.9,3,4.2,1.5,versicolor 64 | 6,2.2,4,1,versicolor 65 | 6.1,2.9,4.7,1.4,versicolor 66 | 5.6,2.9,3.6,1.3,versicolor 67 | 6.7,3.1,4.4,1.4,versicolor 68 | 5.6,3,4.5,1.5,versicolor 69 | 5.8,2.7,4.1,1,versicolor 70 | 6.2,2.2,4.5,1.5,versicolor 71 | 5.6,2.5,3.9,1.1,versicolor 72 | 5.9,3.2,4.8,1.8,versicolor 73 | 6.1,2.8,4,1.3,versicolor 74 | 6.3,2.5,4.9,1.5,versicolor 75 | 6.1,2.8,4.7,1.2,versicolor 76 | 6.4,2.9,4.3,1.3,versicolor 77 | 6.6,3,4.4,1.4,versicolor 78 | 6.8,2.8,4.8,1.4,versicolor 79 | 6.7,3,5,1.7,versicolor 80 | 6,2.9,4.5,1.5,versicolor 81 | 5.7,2.6,3.5,1,versicolor 82 | 5.5,2.4,3.8,1.1,versicolor 83 | 5.5,2.4,3.7,1,versicolor 84 | 5.8,2.7,3.9,1.2,versicolor 85 | 6,2.7,5.1,1.6,versicolor 86 | 5.4,3,4.5,1.5,versicolor 87 | 6,3.4,4.5,1.6,versicolor 88 | 6.7,3.1,4.7,1.5,versicolor 89 | 6.3,2.3,4.4,1.3,versicolor 90 | 5.6,3,4.1,1.3,versicolor 91 | 5.5,2.5,4,1.3,versicolor 92 | 5.5,2.6,4.4,1.2,versicolor 93 | 6.1,3,4.6,1.4,versicolor 94 | 5.8,2.6,4,1.2,versicolor 95 | 5,2.3,3.3,1,versicolor 96 | 5.6,2.7,4.2,1.3,versicolor 97 | 5.7,3,4.2,1.2,versicolor 98 | 5.7,2.9,4.2,1.3,versicolor 99 | 6.2,2.9,4.3,1.3,versicolor 100 | 5.1,2.5,3,1.1,versicolor 101 | 5.7,2.8,4.1,1.3,versicolor 102 | 6.3,3.3,6,2.5,virginica 103 | 5.8,2.7,5.1,1.9,virginica 104 | 7.1,3,5.9,2.1,virginica 105 | 6.3,2.9,5.6,1.8,virginica 106 | 6.5,3,5.8,2.2,virginica 107 | 7.6,3,6.6,2.1,virginica 108 | 4.9,2.5,4.5,1.7,virginica 109 | 7.3,2.9,6.3,1.8,virginica 110 | 6.7,2.5,5.8,1.8,virginica 111 | 7.2,3.6,6.1,2.5,virginica 112 | 6.5,3.2,5.1,2,virginica 113 | 6.4,2.7,5.3,1.9,virginica 114 | 6.8,3,5.5,2.1,virginica 115 | 5.7,2.5,5,2,virginica 116 | 5.8,2.8,5.1,2.4,virginica 117 | 6.4,3.2,5.3,2.3,virginica 118 | 6.5,3,5.5,1.8,virginica 119 | 7.7,3.8,6.7,2.2,virginica 120 | 7.7,2.6,6.9,2.3,virginica 121 | 6,2.2,5,1.5,virginica 122 | 6.9,3.2,5.7,2.3,virginica 123 | 5.6,2.8,4.9,2,virginica 124 | 7.7,2.8,6.7,2,virginica 125 | 6.3,2.7,4.9,1.8,virginica 126 | 6.7,3.3,5.7,2.1,virginica 127 | 7.2,3.2,6,1.8,virginica 128 | 6.2,2.8,4.8,1.8,virginica 129 | 6.1,3,4.9,1.8,virginica 130 | 6.4,2.8,5.6,2.1,virginica 131 | 7.2,3,5.8,1.6,virginica 132 | 7.4,2.8,6.1,1.9,virginica 133 | 7.9,3.8,6.4,2,virginica 134 | 6.4,2.8,5.6,2.2,virginica 135 | 6.3,2.8,5.1,1.5,virginica 136 | 6.1,2.6,5.6,1.4,virginica 137 | 7.7,3,6.1,2.3,virginica 138 | 6.3,3.4,5.6,2.4,virginica 139 | 6.4,3.1,5.5,1.8,virginica 140 | 6,3,4.8,1.8,virginica 141 | 6.9,3.1,5.4,2.1,virginica 142 | 6.7,3.1,5.6,2.4,virginica 143 | 6.9,3.1,5.1,2.3,virginica 144 | 5.8,2.7,5.1,1.9,virginica 145 | 6.8,3.2,5.9,2.3,virginica 146 | 6.7,3.3,5.7,2.5,virginica 147 | 6.7,3,5.2,2.3,virginica 148 | 6.3,2.5,5,1.9,virginica 149 | 6.5,3,5.2,2,virginica 150 | 6.2,3.4,5.4,2.3,virginica 151 | 5.9,3,5.1,1.8,virginica -------------------------------------------------------------------------------- /Students/Sophia/ps1/PS1_writeup.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage[pdftex]{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | \newcommand\ve{\varepsilon} 63 | \newcommand\boldline{\arrayrulewidth{1pt}\hline} 64 | 65 | 66 | \begin{document} 67 | 68 | \begin{flushleft} 69 | \textbf{\large{Problem Set 1}} \\ 70 | MACS 40000, Dr. Evans \\ 71 | Sophia Mo 72 | \end{flushleft} 73 | 74 | \vspace{5mm} 75 | 76 | \noindent\textbf{Problem 2(a)}\\ 77 | The Lagrange function is: 78 | \begin{equation*} 79 | (1-\beta)ln(c_{1,t})+\beta ln(c_{2, {t+1}})-\lambda[p_te_1+p_{t+1}e_2-p_tc_{1,t}-p_{t+1}c_{2, t+1}] 80 | \end{equation*} 81 | The first order conditions are, 82 | \begin{align*} 83 | \frac{1-\beta}{c_{1,t}}&=\lambda p_t\\ 84 | \frac{\beta}{c_{2, {t+1}}}&=\lambda p_{t+1} 85 | \end{align*} 86 | Combining the two equations above, we get 87 | \begin{equation*} 88 | c_{2,{t+1}}=\frac{\beta}{1-\beta}\frac{p_t}{p_{t+1}}c_{1,t} 89 | \end{equation*} 90 | Plugging it into the budget constraint, we get 91 | \begin{align*} 92 | c_{1,t} &= \frac{(p_te_1+p_{t+1}e_2)(1-\beta)}{p_t}\\ 93 | c_{2,t+1}&= \frac{(p_te_1+p_{t+1}e_2)\beta}{p_{t+1}} 94 | \end{align*} 95 | 96 | \noindent\textbf{Problem 2(b)}\\ 97 | Since the utility of initial old increases as her consumption in the second period increases, the initial old would want to exhaust her resource in the last period of her life, so $c_{2,1}=\frac{p_1e_2}{p_1}=e_2$. \\ 98 | \\ 99 | \noindent\textbf{Problem 2(c)}\\ 100 | At competitve equilibrium, the amount of borrowing and lending must be equal for each period. In period 1, the initial old would want to consume all her endowment $e_2$, leaving the young born in period 1 with nothing to borrow and her own endowment $e_1$ to consume. Going into the next period, the individual born in period 1 consumes her period-2 endowment $e_2$, leaving the one born in period 2 with $e_1$ to consume. This reasoning applies to every period--the old in that period consumes all her endowment $e_2$, and the young could only consume all the nonstorable $e_1$. $\{c_{1,t}, c_{2,t}\}_{t=1}^\infty = \{e_1, e_2\} $.\\ 101 | \\ 102 | Since there is no intergenerational transfer going on, prices are indeterminate. The competitive equilibrium is not necessarily equal to my anwer in part (a). Plugging $e_1, e_2$ into the intertemporal euler equation in part (a), we get $\frac{e_2}{e_1}=\frac{\beta}{1-\beta} \frac{p_{t}}{p_{t+1}}$. When normalizing $p_1=1$, we get $p_t = (\frac{\beta}{1-\beta}\frac{e_1}{e_2})^{t-1}$. Only when imposing this vector of prices could we obtain a competitive equilibrium that is same to the answer in part (a). 103 | \end{document} 104 | -------------------------------------------------------------------------------- /Tutorials/LaTeX/LaTeX_probset_template.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage[pdftex]{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | \newcommand\ve{\varepsilon} 63 | \newcommand\boldline{\arrayrulewidth{1pt}\hline} 64 | 65 | 66 | \begin{document} 67 | 68 | \begin{flushleft} 69 | \textbf{\large{Problem Set \#[insert the problem set number]}} \\ 70 | MACS 30000, Dr. Evans \\ 71 | Your Name 72 | \end{flushleft} 73 | 74 | \vspace{5mm} 75 | 76 | \noindent\textbf{Problem 1} 77 | You could put some description here, or you could just list your answer. 78 | \textbf{Part (a).} Put your answer to part (a) here. You might also need to include an equation. 79 | \begin{equation*} 80 | \Omega_{j,t} = \left(\frac{\int_{m=4}^\infty(2t + 7m)dm}{\sum_{x=1}^23\sin(\theta_{j,x})}\right) + 7 81 | \end{equation*} 82 | You could refer to that object from the equation in math mode $\Omega_{j,t}$ in the sentence. Or if you wanted to talk about the equation, you could remove the asterisks, give it a label, and refer to it with references. 83 | \begin{equation}\label{EqCoolness} 84 | \Omega_{j,t} = \left(\frac{\int_{m=4}^\infty(2t + 7m)dm}{\sum_{x=1}^23\sin(\theta_{j,x})}\right) + 7 85 | \end{equation} 86 | Look how cool equation \eqref{EqCoolness} is. 87 | 88 | You might want to include a table in your \LaTeX document. For this, you use the \texttt{tabular} environment. 89 | \begin{table}[htbp] \centering \captionsetup{width=6.0in} 90 | \caption{\label{TabExample}\textbf{Sweet example table}} 91 | \begin{threeparttable} 92 | \begin{tabular}{>{\small}l |>{\small}l >{\small}c |>{\small}r} 93 | \hline\hline 94 | Degrees & Time to completion & happiness (1-10) & added value (1-10) \\ 95 | \hline 96 | High school diploma & 3.9 years & 5 & 2 \\ 97 | Bachelor's degree & 3.8 years & 7 & 5 \\ 98 | Master's degree & 1.7 years & 8 & 4 \\ 99 | PhD & 5.7 years & 3 & 7 \\ 100 | \hline\hline 101 | \end{tabular} 102 | \begin{tablenotes} 103 | \scriptsize{\item[*]With this \texttt{threeparttable} environment, you can add nice subtext to a table.} 104 | \end{tablenotes} 105 | \end{threeparttable} 106 | \end{table} 107 | Lastly, you can add figures to your document. Just make sure that the reference to the figure has the right file path. Figure \ref{FigExample} is pretty nice. But, ideally, you would have something better than a pencil drawing. But you can just place any \texttt{.png} file into the \texttt{includegraphics} command. 108 | \begin{figure}[htb]\centering\captionsetup{width=4.0in} 109 | \caption{\textbf{Great example figure}}\label{FigExample} 110 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{pencildrawing.png}}} 111 | \end{figure} 112 | 113 | 114 | \end{document} 115 | 116 | -------------------------------------------------------------------------------- /Students/Fiona/PS8/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | 7 | 8 | 9 | ''' 10 | Stiching functions for U(c) and g(b) 11 | ''' 12 | def MU_c_stitch(cvec, sigma): 13 | epsilon = 1e-4 14 | c_cnstr = cvec < epsilon 15 | muc = cvec ** (-sigma) 16 | # print (f"cvec:{cvec.shape}") 17 | m1 = (-sigma) * epsilon ** (-sigma - 1) 18 | m2 = epsilon ** (-sigma) - m1 * epsilon 19 | muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 20 | 21 | return muc 22 | 23 | ''' 24 | Firm utilities: 25 | calculate wage and interest rate 26 | ''' 27 | 28 | def get_w(K, L, alpha, A): 29 | return (1-alpha) * A * ((K / L)**alpha) 30 | 31 | def get_r(K,L, alpha, delta, A): 32 | return alpha * A* ((L/ K)**(1-alpha)) - delta 33 | 34 | ''' 35 | Household utilities 36 | ''' 37 | # #Calculate the remaning consumptions in one's lifetime. 38 | 39 | def get_BQ(bvec, r, g_n, omhat, mort_rate): 40 | # print (f'mort:{mort_rate.shape}, omht:{omhat.shape}, bvec:{bvec.shape}') 41 | return ((1 + r) / (1 + g_n)) * (mort_rate[:-1] * omhat[:-1] * bvec).sum() 42 | 43 | 44 | def get_cvec_ss(r, w, bvec, nvec, g_n, g_y, omhat, mort_rate): 45 | #bvec=b2 ~ bS+1 46 | #cvec:c1 ~ cS+1 47 | #nvec:n1 ~ nS+1 48 | b=np.append([0],bvec) 49 | b1=np.append(bvec, [0]) 50 | # print ( f'In getting BQ in cvec, bvec:{bvec.shape}, r:{r}, gn:{g_n}, omhat:{omhat.shape}, mort_rate:{mort_rate.shape}') 51 | bq = get_BQ(bvec, r, g_n, omhat, mort_rate) 52 | # print(f"In getting cvec, bvec shape is: {bvec.shape}, b shape is: {b.shape}, bq {bq}, w {w}, nvec {nvec.shape}, r {r}") 53 | 54 | c_vec = (1 + r) * b + w * nvec - b1*np.exp(g_y) + bq/get_N(omhat) 55 | c_cnstr = c_vec <= 0 56 | # print(f"cvec shape is: {c_vec.shape}") 57 | return c_vec, c_cnstr 58 | 59 | # 60 | def get_cvec_tpi(rpath, wpath, bvec, nvec, g_y, bq, omhat): 61 | # bq_distr, beta = params 62 | #bvec=b1 ~ bS+1TypeError: fsolve: there is a mismatch between the input and output shape of the 'func' argument 'EulerSys_ss'.Shape should be (79,) but it is (78,). 63 | 64 | #cvec:c1 ~ cS 65 | #nvec:n1 ~ nS 66 | b=np.append([0],bvec) 67 | # b1=np.append(bvec,[0]) 68 | # print(f"bvec shape is: {bvec.shape}, b shape is: {b.shape}, bq {bq}, bq_distr {bq_distr.shape}, w {w}, nvec {nvec.shape}, r {r}") c_vec: {c_vec.shape}, 69 | # print (f'b: {b.shape}, rpath{rpath.shape}, wpath:{wpath.shape}, bq_distr{bq_distr.shape}, bq{bq.shape}, nvec{nvec.shape}') 70 | # print (f'bq: {bq.shape}, b:{b.shape}, nvec:{nvec.shape},wpath:{wpath.shape},rpath:{rpath.shape}', bvec.shape) 71 | c_vec = (1 + rpath[:-1]) * b[:-1] + wpath[:-1] * nvec[:-1] - bvec*np.exp(g_y) + bq[:-1] /get_N(omhat) 72 | c_cnstr = c_vec <= 0 73 | # print(f"cvec shape is: {c_vec.shape}") 74 | return c_vec, c_cnstr 75 | 76 | 77 | ######## Euler Equations 78 | 79 | 80 | def EulerSys_ss(vec, *args): 81 | beta, sigma, nvec, A, alpha, delta, g_n,g_y,omhat,mort_rate, imm_rates=args 82 | K= get_K(vec, omhat, g_n, imm_rates) 83 | L=get_L(nvec,omhat) 84 | r=get_r(K, L, alpha, delta, A) 85 | w=get_w(K, L, alpha, A) 86 | # cvec:c1 ~ cS 87 | cvec,c_cnstr=get_cvec_ss(r, w, vec, nvec, g_n, g_y, omhat, mort_rate) 88 | # print (f'ss eur cvec:{cvec.shape}') 89 | # errors=np.zeros(np.shape(vec)) 90 | # MU_c=MU_c_stitch(cvec,sigma) 91 | errors = beta*(1+r)*MU_c_stitch(cvec[1:],sigma)*np.exp(-sigma*g_y)-MU_c_stitch(cvec[:-1],sigma) 92 | return errors 93 | 94 | 95 | def EulerSys_tpi(bvec, *args): 96 | beg_wealth, nvec, beta, sigma, wpath, rpath, BQpath, omhat,g_y = args 97 | # b = np.append(beg_wealth, bvec) 98 | b1 = np.append(bvec,[0]) 99 | b0 = np.append(beg_wealth,bvec) 100 | # print (f'b:{b0.shape,b1.shape}, wpath:{wpath.shape}, nvec:{nvec.shape}, {beg_wealth}') 101 | cvec = (1 + rpath) * b0+ wpath * nvec + BQpath/get_N(omhat) - b1 * np.exp(g_y) 102 | muc = MU_c_stitch(cvec, sigma) 103 | # errors = np.zeros(np.shape(cvec)) 104 | errors = muc[:-1] - beta * (1 + rpath[1:]) * muc[1:] *np.exp((-sigma)*g_y) 105 | 106 | return errors 107 | 108 | 109 | ######## Calculate aggregates 110 | 111 | #from s=1 to S 112 | def get_L(nvec, omhat): # function for aggregate labor supply 113 | return (nvec * omhat).sum() 114 | 115 | # from s=2 to S 116 | def get_K(bhat_vec, omhat, g_n,imm_rates): # function for aggregate capital supply 117 | # print (f'omhat{omhat[:-1].shape}, bhat_vec:{bhat_vec.shape}') 118 | # print (f'In getting K, the shape is {bhat_vec.shape} ') 119 | return (omhat[:-1]*bhat_vec + imm_rates[1:] * omhat[1:] * bhat_vec)[1:].sum()/(1+g_n) 120 | 121 | def get_Y(K, L, params): # function for aggregate output 122 | A, alpha = params 123 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 124 | return Y 125 | 126 | def get_C(carr, omhat): 127 | if carr.ndim == 1: 128 | C = (omhat*carr).sum() 129 | elif carr.ndim == 2: 130 | C = (omhat*carr).sum(axis=0) 131 | 132 | return C 133 | 134 | def get_N (omhat): 135 | return omhat.sum() -------------------------------------------------------------------------------- /Students/Fiona/PS3/TPI2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET 3 4 | Solving TPI for S-period model 5 | Author: Fiona Fan 6 | ''' 7 | import time 8 | import numpy as np 9 | import scipy.optimize as opt 10 | import SS as ss 11 | import matplotlib 12 | import matplotlib.pyplot as plt 13 | from matplotlib.ticker import MultipleLocator 14 | from mpl_toolkits.mplot3d import Axes3D 15 | import sys 16 | import os 17 | 18 | def getPath(x1,xT,T): 19 | return np.linspace(int(x1), int(xT), int(T)) 20 | 21 | 22 | def EulerSys(bvec, *args): 23 | beta, sigma, beg_wealth, nvec, rpath, wpath= args 24 | bvec2 = np.append(beg_wealth, bvec) 25 | # print(nvec.shape) 26 | cvec, c_cnstr = get_cvec(rpath, wpath, nvec, bvec2) 27 | b_err_params = (beta, sigma) 28 | b_err_vec = ss.get_b_errors(b_err_params, rpath[1:], cvec, 29 | c_cnstr) 30 | return b_err_vec 31 | 32 | def get_cvec(rpath, wpath, nvec, bvec): 33 | 34 | b_s = bvec 35 | b_sp1 = np.append(bvec[1:], [0]) 36 | cvec = (1 + rpath) * b_s + wpath * nvec - b_sp1 37 | c_cnstr = cvec <= 0 38 | return cvec, c_cnstr 39 | 40 | def solver(params, beg_age, beg_wealth, nvec, rpath, wpath, b_init): 41 | 42 | S, beta, sigma, TPI_tol = params 43 | p = int(S - beg_age + 1) 44 | b_guess = 1.01 * b_init 45 | eullf_objs = (beta, sigma, beg_wealth, nvec, rpath, wpath) 46 | bpath = opt.root(EulerSys, b_guess, args=(eullf_objs)).x 47 | bvec=np.append(beg_wealth, bpath) 48 | cpath, c_cnstr = get_cvec(rpath, wpath, nvec, bvec) 49 | b_err_params = (beta, sigma) 50 | b_err_vec = ss.get_b_errors(b_err_params, rpath[1:], cpath, c_cnstr) 51 | return bpath, cpath, b_err_vec 52 | 53 | 54 | def get_cbepath(params,rpath,wpath): 55 | S, T, beta, sigma, nvec, bvec1, b_ss, TPI_tol = params 56 | cpath = np.zeros((S, T + S - 2)) 57 | bpath=np.zeros((S - 1, T + S - 2)) 58 | EulErrPath = np.zeros((S - 1, T + S - 2)) 59 | bpath[:, 0] = bvec1 60 | cpath[S - 1, 0] = ((1 + rpath[0]) * bvec1[S - 2] + wpath[0] * nvec[S - 1]) 61 | sol_params = (S, beta, sigma, TPI_tol) 62 | 63 | #solve remaining lifetime decisions 64 | for p in range(2, S): 65 | b_guess = np.diagonal(bpath[S - p:, :p - 1]) 66 | bveclf, cveclf, b_err_veclf = solver( 67 | sol_params, S - p + 1, bvec1[S - p - 1], nvec[-p:], 68 | rpath[:p], wpath[:p], b_guess) 69 | 70 | DiagMaskb = np.eye(p - 1, dtype=bool) 71 | DiagMaskc = np.eye(p, dtype=bool) 72 | bpath[S - p:, 1:p] = DiagMaskb * bveclf + bpath[S - p:, 1:p] 73 | cpath[S - p:, :p] = DiagMaskc * cveclf + cpath[S - p:, :p] 74 | EulErrPath[S - p:, 1:p] = (DiagMaskb * b_err_veclf + 75 | EulErrPath[S - p:, 1:p]) 76 | 77 | # solve complete lifetime decisions 78 | DiagMaskb = np.eye(S - 1, dtype=bool) 79 | DiagMaskc = np.eye(S, dtype=bool) 80 | for t in range(1, T): # Go from periods 1 to T-1 81 | b_guess = np.diagonal(bpath[:, t - 1:t + S - 2]) 82 | bveclf, cveclf, b_err_veclf = solver( 83 | sol_params, 1, 0, nvec, rpath[t - 1:t + S - 1], 84 | wpath[t - 1:t + S - 1], b_guess) 85 | bpath[:, t:t + S - 1] = (DiagMaskb * bveclf + 86 | bpath[:, t:t + S - 1]) 87 | cpath[:, t - 1:t + S - 1] = (DiagMaskc * cveclf + 88 | cpath[:, t - 1:t + S - 1]) 89 | EulErrPath[:, t:t + S - 1] = (DiagMaskb * b_err_veclf + 90 | EulErrPath[:, t:t + S - 1]) 91 | 92 | return cpath, bpath, EulErrPath 93 | 94 | def get_TPI(params,bvec,graphs): 95 | start_time = time.clock() 96 | (S,T, beta, sigma, nvec, L, A, alpha, delta, b_ss, K_ss,C_ss, 97 | maxiter_TPI, mindist_TPI, xi,TPI_tol) = params 98 | 99 | abs2 = 1 100 | tpi_iter = 0 101 | cbe_params = (S, T, beta, sigma, nvec, bvec, b_ss, TPI_tol) 102 | L = ss.get_L(nvec) 103 | K1 = ss.get_K(bvec)[0] 104 | Kpath_old = np.zeros(T + S-2) 105 | Kpath_old[:T] = getPath(K1, K_ss, T) 106 | Kpath_old[T:] = K_ss 107 | Kpath_new=Kpath_old.copy() 108 | 109 | while abs2 > mindist_TPI and tpi_iter < maxiter_TPI: 110 | tpi_iter += 1 111 | w_path = ss.get_w((A, alpha), Kpath_old, L) 112 | r_path = ss.get_r((A, alpha, delta), Kpath_old, L) 113 | Kpath_old = xi * Kpath_new + (1 - xi) * Kpath_old 114 | cpath, bpath, EulErrPath = get_cbepath(cbe_params, r_path, w_path) 115 | #print(bvec) 116 | Kpath_new = np.zeros(T + S - 2) 117 | Kpath_new[:T] = ss.get_K(bpath[:, :T])[0] 118 | Kpath_new[T:] = K_ss 119 | abs2 = (((Kpath_new[1:T] - Kpath_old[1:T])/Kpath_old[1:T]*100) ** 2).sum() 120 | print('iteration:', tpi_iter, 'squared pct deviation sum: ', abs2) 121 | 122 | tpi_time = time.clock() - start_time 123 | print(f'It took {tpi_time} seconds to run.') 124 | 125 | Kpath = Kpath_new 126 | Ypath = ss.get_Y((A, alpha), Kpath, L) 127 | Cpath = np.zeros(T + S - 2) 128 | Cpath[:T - 1] = ss.get_C(cpath[:, :T - 1]) 129 | Cpath[T - 1:] = C_ss * np.ones(S - 1) 130 | RCerrPath = (Ypath[:-1] - Cpath[:-1] - Kpath[1:] + 131 | (1 - delta) * Kpath[:-1]) 132 | tpi_output = { 133 | 'bpath': bpath, 'cpath': cpath, 'wpath': w_path, 'rpath': r_path, 134 | 'Kpath': Kpath_new, 'Ypath': Ypath, 'Cpath': Cpath, 135 | 'EulErrPath': EulErrPath, 'RCerrPath': RCerrPath, 136 | 'tpi_time': tpi_time} 137 | 138 | return tpi_output -------------------------------------------------------------------------------- /ProblemSets/PS7/mort_rates2011.csv: -------------------------------------------------------------------------------- 1 | Age,Male Mort. Rate,Num. Male Lives,Male Life Exp.,Female Mort. Rate,Num. Female Lives,Female Life Exp. 0,0.006569,"100,000",76.18,0.005513,"100,000",80.95 1,0.000444,"99,343",75.69,0.000382,"99,449",80.39 2,0.000291,"99,299",74.72,0.000218,"99,411",79.42 3,0.000226,"99,270",73.74,0.000166,"99,389",78.44 4,0.000173,"99,248",72.76,0.000143,"99,373",77.45 5,0.000158,"99,230",71.77,0.000127,"99,358",76.47 6,0.000147,"99,215",70.78,0.000116,"99,346",75.48 7,0.000136,"99,200",69.79,0.000106,"99,334",74.48 8,0.000121,"99,187",68.8,0.000098,"99,324",73.49 9,0.000104,"99,175",67.81,0.000091,"99,314",72.5 10,0.000092,"99,164",66.82,0.000086,"99,305",71.51 11,0.000097,"99,155",65.82,0.000089,"99,296",70.51 12,0.000134,"99,146",64.83,0.000102,"99,288",69.52 13,0.00021,"99,132",63.84,0.000128,"99,277",68.52 14,0.000317,"99,112",62.85,0.000164,"99,265",67.53 15,0.000433,"99,080",61.87,0.000205,"99,248",66.54 16,0.000547,"99,037",60.9,0.000246,"99,228",65.56 17,0.000672,"98,983",59.93,0.000285,"99,204",64.57 18,0.000805,"98,917",58.97,0.000319,"99,175",63.59 19,0.000941,"98,837",58.02,0.00035,"99,144",62.61 20,0.001084,"98,744",57.07,0.000383,"99,109",61.63 21,0.001219,"98,637",56.13,0.000417,"99,071",60.66 22,0.001314,"98,517",55.2,0.000446,"99,030",59.68 23,0.001357,"98,387",54.27,0.000469,"98,986",58.71 24,0.001362,"98,254",53.35,0.000487,"98,939",57.74 25,0.001353,"98,120",52.42,0.000505,"98,891",56.76 26,0.00135,"97,987",51.49,0.000525,"98,841",55.79 27,0.001353,"97,855",50.56,0.000551,"98,789",54.82 28,0.001371,"97,722",49.63,0.000585,"98,735",53.85 29,0.001399,"97,588",48.69,0.000626,"98,677",52.88 30,0.001432,"97,452",47.76,0.000672,"98,615",51.92 31,0.001464,"97,312",46.83,0.00072,"98,549",50.95 32,0.001497,"97,170",45.9,0.000766,"98,478",49.99 33,0.00153,"97,024",44.96,0.000806,"98,403",49.02 34,0.001568,"96,876",44.03,0.000846,"98,323",48.06 35,0.001617,"96,724",43.1,0.000891,"98,240",47.1 36,0.001682,"96,568",42.17,0.000946,"98,153",46.15 37,0.001759,"96,405",41.24,0.001013,"98,060",45.19 38,0.001852,"96,236",40.31,0.001094,"97,960",44.23 39,0.001963,"96,057",39.39,0.00119,"97,853",43.28 40,0.002092,"95,869",38.46,0.001296,"97,737",42.33 41,0.002246,"95,668",37.54,0.001413,"97,610",41.39 42,0.002436,"95,453",36.62,0.001549,"97,472",40.45 43,0.002669,"95,221",35.71,0.001706,"97,321",39.51 44,0.002942,"94,967",34.81,0.001881,"97,155",38.57 45,0.003244,"94,687",33.91,0.002069,"96,972",37.65 46,0.003571,"94,380",33.02,0.00227,"96,772",36.72 47,0.003926,"94,043",32.13,0.002486,"96,552",35.81 48,0.004309,"93,674",31.26,0.002716,"96,312",34.89 49,0.004719,"93,270",30.39,0.00296,"96,050",33.99 50,0.005156,"92,830",29.53,0.003226,"95,766",33.09 51,0.005622,"92,352",28.68,0.003505,"95,457",32.19 52,0.006121,"91,832",27.84,0.003779,"95,123",31.3 53,0.006656,"91,270",27.01,0.00404,"94,763",30.42 54,0.007222,"90,663",26.19,0.004301,"94,380",29.54 55,0.007844,"90,008",25.38,0.004592,"93,974",28.67 56,0.008493,"89,302",24.57,0.00492,"93,543",27.8 57,0.009116,"88,544",23.78,0.005266,"93,083",26.93 58,0.00969,"87,736",22.99,0.00563,"92,592",26.07 59,0.010253,"86,886",22.21,0.006028,"92,071",25.22 60,0.010872,"85,995",21.44,0.006479,"91,516",24.37 61,0.011591,"85,060",20.67,0.007001,"90,923",23.52 62,0.012403,"84,075",19.9,0.007602,"90,287",22.68 63,0.013325,"83,032",19.15,0.008294,"89,600",21.85 64,0.01437,"81,925",18.4,0.009082,"88,857",21.03 65,0.015553,"80,748",17.66,0.00999,"88,050",20.22 66,0.016878,"79,492",16.93,0.011005,"87,171",19.42 67,0.018348,"78,151",16.21,0.012097,"86,211",18.63 68,0.019969,"76,717",15.51,0.013261,"85,168",17.85 69,0.021766,"75,185",14.81,0.014529,"84,039",17.09 70,0.02384,"73,548",14.13,0.015991,"82,818",16.33 71,0.026162,"71,795",13.47,0.017662,"81,494",15.59 72,0.028625,"69,917",12.81,0.019486,"80,054",14.86 73,0.031204,"67,915",12.18,0.021467,"78,494",14.14 74,0.033997,"65,796",11.55,0.023658,"76,809",13.44 75,0.0372,"63,559",10.94,0.026223,"74,992",12.76 76,0.040898,"61,195",10.34,0.029159,"73,026",12.09 77,0.04504,"58,692",9.76,0.032331,"70,896",11.44 78,0.049664,"56,048",9.2,0.035725,"68,604",10.8 79,0.054844,"53,265",8.66,0.039469,"66,153",10.18 80,0.060801,"50,344",8.13,0.043828,"63,542",9.58 81,0.067509,"47,283",7.62,0.048896,"60,757",9 82,0.074779,"44,091",7.14,0.054577,"57,786",8.43 83,0.082589,"40,794",6.68,0.060909,"54,633",7.89 84,0.091135,"37,424",6.23,0.068019,"51,305",7.37 85,0.10068,"34,014",5.81,0.076054,"47,815",6.87 86,0.111444,"30,589",5.4,0.085148,"44,179",6.4 87,0.123571,"27,180",5.02,0.095395,"40,417",5.94 88,0.137126,"23,822",4.65,0.106857,"36,561",5.52 89,0.152092,"20,555",4.31,0.119557,"32,655",5.12 90,0.168426,"17,429",4,0.133502,"28,751",4.75 91,0.186063,"14,493",3.7,0.148685,"24,912",4.4 92,0.204925,"11,797",3.44,0.165088,"21,208",4.08 93,0.224931,"9,379",3.19,0.182685,"17,707",3.79 94,0.245995,"7,270",2.97,0.201442,"14,472",3.53 95,0.266884,"5,481",2.78,0.220406,"11,557",3.29 96,0.287218,"4,018",2.61,0.239273,"9,010",3.08 97,0.306593,"2,864",2.46,0.257714,"6,854",2.89 98,0.324599,"1,986",2.33,0.275376,"5,088",2.72 99,0.340829,"1,341",2.21,0.291899,"3,687",2.56 100,0.35787,884,2.09,0.309413,"2,610",2.41 101,0.375764,568,1.98,0.327978,"1,803",2.27 102,0.394552,354,1.88,0.347656,"1,211",2.13 103,0.41428,215,1.77,0.368516,790,2 104,0.434993,126,1.68,0.390627,499,1.87 105,0.456743,71,1.58,0.414064,304,1.75 106,0.47958,39,1.49,0.438908,178,1.64 107,0.503559,20,1.4,0.465243,100,1.53 108,0.528737,10,1.32,0.493157,53,1.43 109,0.555174,5,1.24,0.522747,27,1.33 110,0.582933,2,1.16,0.554111,13,1.23 111,0.61208,1,1.09,0.587358,6,1.14 112,0.642683,0,1.02,0.622599,2,1.06 113,0.674818,0,0.95,0.659955,1,0.98 114,0.708559,0,0.89,0.699553,0,0.9 115,0.743986,0,0.82,0.741526,0,0.83 116,0.781186,0,0.76,0.781186,0,0.76 117,0.820245,0,0.71,0.820245,0,0.71 118,0.861257,0,0.65,0.861257,0,0.65 119,0.90432,0,0.6,0.90432,0,0.6 -------------------------------------------------------------------------------- /Students/Fiona/PS7/mort_rates2011.csv: -------------------------------------------------------------------------------- 1 | Age,Male Mort. Rate,Num. Male Lives,Male Life Exp.,Female Mort. Rate,Num. Female Lives,Female Life Exp. 0,0.006569,"100,000",76.18,0.005513,"100,000",80.95 1,0.000444,"99,343",75.69,0.000382,"99,449",80.39 2,0.000291,"99,299",74.72,0.000218,"99,411",79.42 3,0.000226,"99,270",73.74,0.000166,"99,389",78.44 4,0.000173,"99,248",72.76,0.000143,"99,373",77.45 5,0.000158,"99,230",71.77,0.000127,"99,358",76.47 6,0.000147,"99,215",70.78,0.000116,"99,346",75.48 7,0.000136,"99,200",69.79,0.000106,"99,334",74.48 8,0.000121,"99,187",68.8,0.000098,"99,324",73.49 9,0.000104,"99,175",67.81,0.000091,"99,314",72.5 10,0.000092,"99,164",66.82,0.000086,"99,305",71.51 11,0.000097,"99,155",65.82,0.000089,"99,296",70.51 12,0.000134,"99,146",64.83,0.000102,"99,288",69.52 13,0.00021,"99,132",63.84,0.000128,"99,277",68.52 14,0.000317,"99,112",62.85,0.000164,"99,265",67.53 15,0.000433,"99,080",61.87,0.000205,"99,248",66.54 16,0.000547,"99,037",60.9,0.000246,"99,228",65.56 17,0.000672,"98,983",59.93,0.000285,"99,204",64.57 18,0.000805,"98,917",58.97,0.000319,"99,175",63.59 19,0.000941,"98,837",58.02,0.00035,"99,144",62.61 20,0.001084,"98,744",57.07,0.000383,"99,109",61.63 21,0.001219,"98,637",56.13,0.000417,"99,071",60.66 22,0.001314,"98,517",55.2,0.000446,"99,030",59.68 23,0.001357,"98,387",54.27,0.000469,"98,986",58.71 24,0.001362,"98,254",53.35,0.000487,"98,939",57.74 25,0.001353,"98,120",52.42,0.000505,"98,891",56.76 26,0.00135,"97,987",51.49,0.000525,"98,841",55.79 27,0.001353,"97,855",50.56,0.000551,"98,789",54.82 28,0.001371,"97,722",49.63,0.000585,"98,735",53.85 29,0.001399,"97,588",48.69,0.000626,"98,677",52.88 30,0.001432,"97,452",47.76,0.000672,"98,615",51.92 31,0.001464,"97,312",46.83,0.00072,"98,549",50.95 32,0.001497,"97,170",45.9,0.000766,"98,478",49.99 33,0.00153,"97,024",44.96,0.000806,"98,403",49.02 34,0.001568,"96,876",44.03,0.000846,"98,323",48.06 35,0.001617,"96,724",43.1,0.000891,"98,240",47.1 36,0.001682,"96,568",42.17,0.000946,"98,153",46.15 37,0.001759,"96,405",41.24,0.001013,"98,060",45.19 38,0.001852,"96,236",40.31,0.001094,"97,960",44.23 39,0.001963,"96,057",39.39,0.00119,"97,853",43.28 40,0.002092,"95,869",38.46,0.001296,"97,737",42.33 41,0.002246,"95,668",37.54,0.001413,"97,610",41.39 42,0.002436,"95,453",36.62,0.001549,"97,472",40.45 43,0.002669,"95,221",35.71,0.001706,"97,321",39.51 44,0.002942,"94,967",34.81,0.001881,"97,155",38.57 45,0.003244,"94,687",33.91,0.002069,"96,972",37.65 46,0.003571,"94,380",33.02,0.00227,"96,772",36.72 47,0.003926,"94,043",32.13,0.002486,"96,552",35.81 48,0.004309,"93,674",31.26,0.002716,"96,312",34.89 49,0.004719,"93,270",30.39,0.00296,"96,050",33.99 50,0.005156,"92,830",29.53,0.003226,"95,766",33.09 51,0.005622,"92,352",28.68,0.003505,"95,457",32.19 52,0.006121,"91,832",27.84,0.003779,"95,123",31.3 53,0.006656,"91,270",27.01,0.00404,"94,763",30.42 54,0.007222,"90,663",26.19,0.004301,"94,380",29.54 55,0.007844,"90,008",25.38,0.004592,"93,974",28.67 56,0.008493,"89,302",24.57,0.00492,"93,543",27.8 57,0.009116,"88,544",23.78,0.005266,"93,083",26.93 58,0.00969,"87,736",22.99,0.00563,"92,592",26.07 59,0.010253,"86,886",22.21,0.006028,"92,071",25.22 60,0.010872,"85,995",21.44,0.006479,"91,516",24.37 61,0.011591,"85,060",20.67,0.007001,"90,923",23.52 62,0.012403,"84,075",19.9,0.007602,"90,287",22.68 63,0.013325,"83,032",19.15,0.008294,"89,600",21.85 64,0.01437,"81,925",18.4,0.009082,"88,857",21.03 65,0.015553,"80,748",17.66,0.00999,"88,050",20.22 66,0.016878,"79,492",16.93,0.011005,"87,171",19.42 67,0.018348,"78,151",16.21,0.012097,"86,211",18.63 68,0.019969,"76,717",15.51,0.013261,"85,168",17.85 69,0.021766,"75,185",14.81,0.014529,"84,039",17.09 70,0.02384,"73,548",14.13,0.015991,"82,818",16.33 71,0.026162,"71,795",13.47,0.017662,"81,494",15.59 72,0.028625,"69,917",12.81,0.019486,"80,054",14.86 73,0.031204,"67,915",12.18,0.021467,"78,494",14.14 74,0.033997,"65,796",11.55,0.023658,"76,809",13.44 75,0.0372,"63,559",10.94,0.026223,"74,992",12.76 76,0.040898,"61,195",10.34,0.029159,"73,026",12.09 77,0.04504,"58,692",9.76,0.032331,"70,896",11.44 78,0.049664,"56,048",9.2,0.035725,"68,604",10.8 79,0.054844,"53,265",8.66,0.039469,"66,153",10.18 80,0.060801,"50,344",8.13,0.043828,"63,542",9.58 81,0.067509,"47,283",7.62,0.048896,"60,757",9 82,0.074779,"44,091",7.14,0.054577,"57,786",8.43 83,0.082589,"40,794",6.68,0.060909,"54,633",7.89 84,0.091135,"37,424",6.23,0.068019,"51,305",7.37 85,0.10068,"34,014",5.81,0.076054,"47,815",6.87 86,0.111444,"30,589",5.4,0.085148,"44,179",6.4 87,0.123571,"27,180",5.02,0.095395,"40,417",5.94 88,0.137126,"23,822",4.65,0.106857,"36,561",5.52 89,0.152092,"20,555",4.31,0.119557,"32,655",5.12 90,0.168426,"17,429",4,0.133502,"28,751",4.75 91,0.186063,"14,493",3.7,0.148685,"24,912",4.4 92,0.204925,"11,797",3.44,0.165088,"21,208",4.08 93,0.224931,"9,379",3.19,0.182685,"17,707",3.79 94,0.245995,"7,270",2.97,0.201442,"14,472",3.53 95,0.266884,"5,481",2.78,0.220406,"11,557",3.29 96,0.287218,"4,018",2.61,0.239273,"9,010",3.08 97,0.306593,"2,864",2.46,0.257714,"6,854",2.89 98,0.324599,"1,986",2.33,0.275376,"5,088",2.72 99,0.340829,"1,341",2.21,0.291899,"3,687",2.56 100,0.35787,884,2.09,0.309413,"2,610",2.41 101,0.375764,568,1.98,0.327978,"1,803",2.27 102,0.394552,354,1.88,0.347656,"1,211",2.13 103,0.41428,215,1.77,0.368516,790,2 104,0.434993,126,1.68,0.390627,499,1.87 105,0.456743,71,1.58,0.414064,304,1.75 106,0.47958,39,1.49,0.438908,178,1.64 107,0.503559,20,1.4,0.465243,100,1.53 108,0.528737,10,1.32,0.493157,53,1.43 109,0.555174,5,1.24,0.522747,27,1.33 110,0.582933,2,1.16,0.554111,13,1.23 111,0.61208,1,1.09,0.587358,6,1.14 112,0.642683,0,1.02,0.622599,2,1.06 113,0.674818,0,0.95,0.659955,1,0.98 114,0.708559,0,0.89,0.699553,0,0.9 115,0.743986,0,0.82,0.741526,0,0.83 116,0.781186,0,0.76,0.781186,0,0.76 117,0.820245,0,0.71,0.820245,0,0.71 118,0.861257,0,0.65,0.861257,0,0.65 119,0.90432,0,0.6,0.90432,0,0.6 -------------------------------------------------------------------------------- /Students/Fiona/PS8/mort_rates2011.csv: -------------------------------------------------------------------------------- 1 | Age,Male Mort. Rate,Num. Male Lives,Male Life Exp.,Female Mort. Rate,Num. Female Lives,Female Life Exp. 0,0.006569,"100,000",76.18,0.005513,"100,000",80.95 1,0.000444,"99,343",75.69,0.000382,"99,449",80.39 2,0.000291,"99,299",74.72,0.000218,"99,411",79.42 3,0.000226,"99,270",73.74,0.000166,"99,389",78.44 4,0.000173,"99,248",72.76,0.000143,"99,373",77.45 5,0.000158,"99,230",71.77,0.000127,"99,358",76.47 6,0.000147,"99,215",70.78,0.000116,"99,346",75.48 7,0.000136,"99,200",69.79,0.000106,"99,334",74.48 8,0.000121,"99,187",68.8,0.000098,"99,324",73.49 9,0.000104,"99,175",67.81,0.000091,"99,314",72.5 10,0.000092,"99,164",66.82,0.000086,"99,305",71.51 11,0.000097,"99,155",65.82,0.000089,"99,296",70.51 12,0.000134,"99,146",64.83,0.000102,"99,288",69.52 13,0.00021,"99,132",63.84,0.000128,"99,277",68.52 14,0.000317,"99,112",62.85,0.000164,"99,265",67.53 15,0.000433,"99,080",61.87,0.000205,"99,248",66.54 16,0.000547,"99,037",60.9,0.000246,"99,228",65.56 17,0.000672,"98,983",59.93,0.000285,"99,204",64.57 18,0.000805,"98,917",58.97,0.000319,"99,175",63.59 19,0.000941,"98,837",58.02,0.00035,"99,144",62.61 20,0.001084,"98,744",57.07,0.000383,"99,109",61.63 21,0.001219,"98,637",56.13,0.000417,"99,071",60.66 22,0.001314,"98,517",55.2,0.000446,"99,030",59.68 23,0.001357,"98,387",54.27,0.000469,"98,986",58.71 24,0.001362,"98,254",53.35,0.000487,"98,939",57.74 25,0.001353,"98,120",52.42,0.000505,"98,891",56.76 26,0.00135,"97,987",51.49,0.000525,"98,841",55.79 27,0.001353,"97,855",50.56,0.000551,"98,789",54.82 28,0.001371,"97,722",49.63,0.000585,"98,735",53.85 29,0.001399,"97,588",48.69,0.000626,"98,677",52.88 30,0.001432,"97,452",47.76,0.000672,"98,615",51.92 31,0.001464,"97,312",46.83,0.00072,"98,549",50.95 32,0.001497,"97,170",45.9,0.000766,"98,478",49.99 33,0.00153,"97,024",44.96,0.000806,"98,403",49.02 34,0.001568,"96,876",44.03,0.000846,"98,323",48.06 35,0.001617,"96,724",43.1,0.000891,"98,240",47.1 36,0.001682,"96,568",42.17,0.000946,"98,153",46.15 37,0.001759,"96,405",41.24,0.001013,"98,060",45.19 38,0.001852,"96,236",40.31,0.001094,"97,960",44.23 39,0.001963,"96,057",39.39,0.00119,"97,853",43.28 40,0.002092,"95,869",38.46,0.001296,"97,737",42.33 41,0.002246,"95,668",37.54,0.001413,"97,610",41.39 42,0.002436,"95,453",36.62,0.001549,"97,472",40.45 43,0.002669,"95,221",35.71,0.001706,"97,321",39.51 44,0.002942,"94,967",34.81,0.001881,"97,155",38.57 45,0.003244,"94,687",33.91,0.002069,"96,972",37.65 46,0.003571,"94,380",33.02,0.00227,"96,772",36.72 47,0.003926,"94,043",32.13,0.002486,"96,552",35.81 48,0.004309,"93,674",31.26,0.002716,"96,312",34.89 49,0.004719,"93,270",30.39,0.00296,"96,050",33.99 50,0.005156,"92,830",29.53,0.003226,"95,766",33.09 51,0.005622,"92,352",28.68,0.003505,"95,457",32.19 52,0.006121,"91,832",27.84,0.003779,"95,123",31.3 53,0.006656,"91,270",27.01,0.00404,"94,763",30.42 54,0.007222,"90,663",26.19,0.004301,"94,380",29.54 55,0.007844,"90,008",25.38,0.004592,"93,974",28.67 56,0.008493,"89,302",24.57,0.00492,"93,543",27.8 57,0.009116,"88,544",23.78,0.005266,"93,083",26.93 58,0.00969,"87,736",22.99,0.00563,"92,592",26.07 59,0.010253,"86,886",22.21,0.006028,"92,071",25.22 60,0.010872,"85,995",21.44,0.006479,"91,516",24.37 61,0.011591,"85,060",20.67,0.007001,"90,923",23.52 62,0.012403,"84,075",19.9,0.007602,"90,287",22.68 63,0.013325,"83,032",19.15,0.008294,"89,600",21.85 64,0.01437,"81,925",18.4,0.009082,"88,857",21.03 65,0.015553,"80,748",17.66,0.00999,"88,050",20.22 66,0.016878,"79,492",16.93,0.011005,"87,171",19.42 67,0.018348,"78,151",16.21,0.012097,"86,211",18.63 68,0.019969,"76,717",15.51,0.013261,"85,168",17.85 69,0.021766,"75,185",14.81,0.014529,"84,039",17.09 70,0.02384,"73,548",14.13,0.015991,"82,818",16.33 71,0.026162,"71,795",13.47,0.017662,"81,494",15.59 72,0.028625,"69,917",12.81,0.019486,"80,054",14.86 73,0.031204,"67,915",12.18,0.021467,"78,494",14.14 74,0.033997,"65,796",11.55,0.023658,"76,809",13.44 75,0.0372,"63,559",10.94,0.026223,"74,992",12.76 76,0.040898,"61,195",10.34,0.029159,"73,026",12.09 77,0.04504,"58,692",9.76,0.032331,"70,896",11.44 78,0.049664,"56,048",9.2,0.035725,"68,604",10.8 79,0.054844,"53,265",8.66,0.039469,"66,153",10.18 80,0.060801,"50,344",8.13,0.043828,"63,542",9.58 81,0.067509,"47,283",7.62,0.048896,"60,757",9 82,0.074779,"44,091",7.14,0.054577,"57,786",8.43 83,0.082589,"40,794",6.68,0.060909,"54,633",7.89 84,0.091135,"37,424",6.23,0.068019,"51,305",7.37 85,0.10068,"34,014",5.81,0.076054,"47,815",6.87 86,0.111444,"30,589",5.4,0.085148,"44,179",6.4 87,0.123571,"27,180",5.02,0.095395,"40,417",5.94 88,0.137126,"23,822",4.65,0.106857,"36,561",5.52 89,0.152092,"20,555",4.31,0.119557,"32,655",5.12 90,0.168426,"17,429",4,0.133502,"28,751",4.75 91,0.186063,"14,493",3.7,0.148685,"24,912",4.4 92,0.204925,"11,797",3.44,0.165088,"21,208",4.08 93,0.224931,"9,379",3.19,0.182685,"17,707",3.79 94,0.245995,"7,270",2.97,0.201442,"14,472",3.53 95,0.266884,"5,481",2.78,0.220406,"11,557",3.29 96,0.287218,"4,018",2.61,0.239273,"9,010",3.08 97,0.306593,"2,864",2.46,0.257714,"6,854",2.89 98,0.324599,"1,986",2.33,0.275376,"5,088",2.72 99,0.340829,"1,341",2.21,0.291899,"3,687",2.56 100,0.35787,884,2.09,0.309413,"2,610",2.41 101,0.375764,568,1.98,0.327978,"1,803",2.27 102,0.394552,354,1.88,0.347656,"1,211",2.13 103,0.41428,215,1.77,0.368516,790,2 104,0.434993,126,1.68,0.390627,499,1.87 105,0.456743,71,1.58,0.414064,304,1.75 106,0.47958,39,1.49,0.438908,178,1.64 107,0.503559,20,1.4,0.465243,100,1.53 108,0.528737,10,1.32,0.493157,53,1.43 109,0.555174,5,1.24,0.522747,27,1.33 110,0.582933,2,1.16,0.554111,13,1.23 111,0.61208,1,1.09,0.587358,6,1.14 112,0.642683,0,1.02,0.622599,2,1.06 113,0.674818,0,0.95,0.659955,1,0.98 114,0.708559,0,0.89,0.699553,0,0.9 115,0.743986,0,0.82,0.741526,0,0.83 116,0.781186,0,0.76,0.781186,0,0.76 117,0.820245,0,0.71,0.820245,0,0.71 118,0.861257,0,0.65,0.861257,0,0.65 119,0.90432,0,0.6,0.90432,0,0.6 -------------------------------------------------------------------------------- /Students/Sophia/ps8/mort_rates2011.csv: -------------------------------------------------------------------------------- 1 | Age,Male Mort. Rate,Num. Male Lives,Male Life Exp.,Female Mort. Rate,Num. Female Lives,Female Life Exp. 0,0.006569,"100,000",76.18,0.005513,"100,000",80.95 1,0.000444,"99,343",75.69,0.000382,"99,449",80.39 2,0.000291,"99,299",74.72,0.000218,"99,411",79.42 3,0.000226,"99,270",73.74,0.000166,"99,389",78.44 4,0.000173,"99,248",72.76,0.000143,"99,373",77.45 5,0.000158,"99,230",71.77,0.000127,"99,358",76.47 6,0.000147,"99,215",70.78,0.000116,"99,346",75.48 7,0.000136,"99,200",69.79,0.000106,"99,334",74.48 8,0.000121,"99,187",68.8,0.000098,"99,324",73.49 9,0.000104,"99,175",67.81,0.000091,"99,314",72.5 10,0.000092,"99,164",66.82,0.000086,"99,305",71.51 11,0.000097,"99,155",65.82,0.000089,"99,296",70.51 12,0.000134,"99,146",64.83,0.000102,"99,288",69.52 13,0.00021,"99,132",63.84,0.000128,"99,277",68.52 14,0.000317,"99,112",62.85,0.000164,"99,265",67.53 15,0.000433,"99,080",61.87,0.000205,"99,248",66.54 16,0.000547,"99,037",60.9,0.000246,"99,228",65.56 17,0.000672,"98,983",59.93,0.000285,"99,204",64.57 18,0.000805,"98,917",58.97,0.000319,"99,175",63.59 19,0.000941,"98,837",58.02,0.00035,"99,144",62.61 20,0.001084,"98,744",57.07,0.000383,"99,109",61.63 21,0.001219,"98,637",56.13,0.000417,"99,071",60.66 22,0.001314,"98,517",55.2,0.000446,"99,030",59.68 23,0.001357,"98,387",54.27,0.000469,"98,986",58.71 24,0.001362,"98,254",53.35,0.000487,"98,939",57.74 25,0.001353,"98,120",52.42,0.000505,"98,891",56.76 26,0.00135,"97,987",51.49,0.000525,"98,841",55.79 27,0.001353,"97,855",50.56,0.000551,"98,789",54.82 28,0.001371,"97,722",49.63,0.000585,"98,735",53.85 29,0.001399,"97,588",48.69,0.000626,"98,677",52.88 30,0.001432,"97,452",47.76,0.000672,"98,615",51.92 31,0.001464,"97,312",46.83,0.00072,"98,549",50.95 32,0.001497,"97,170",45.9,0.000766,"98,478",49.99 33,0.00153,"97,024",44.96,0.000806,"98,403",49.02 34,0.001568,"96,876",44.03,0.000846,"98,323",48.06 35,0.001617,"96,724",43.1,0.000891,"98,240",47.1 36,0.001682,"96,568",42.17,0.000946,"98,153",46.15 37,0.001759,"96,405",41.24,0.001013,"98,060",45.19 38,0.001852,"96,236",40.31,0.001094,"97,960",44.23 39,0.001963,"96,057",39.39,0.00119,"97,853",43.28 40,0.002092,"95,869",38.46,0.001296,"97,737",42.33 41,0.002246,"95,668",37.54,0.001413,"97,610",41.39 42,0.002436,"95,453",36.62,0.001549,"97,472",40.45 43,0.002669,"95,221",35.71,0.001706,"97,321",39.51 44,0.002942,"94,967",34.81,0.001881,"97,155",38.57 45,0.003244,"94,687",33.91,0.002069,"96,972",37.65 46,0.003571,"94,380",33.02,0.00227,"96,772",36.72 47,0.003926,"94,043",32.13,0.002486,"96,552",35.81 48,0.004309,"93,674",31.26,0.002716,"96,312",34.89 49,0.004719,"93,270",30.39,0.00296,"96,050",33.99 50,0.005156,"92,830",29.53,0.003226,"95,766",33.09 51,0.005622,"92,352",28.68,0.003505,"95,457",32.19 52,0.006121,"91,832",27.84,0.003779,"95,123",31.3 53,0.006656,"91,270",27.01,0.00404,"94,763",30.42 54,0.007222,"90,663",26.19,0.004301,"94,380",29.54 55,0.007844,"90,008",25.38,0.004592,"93,974",28.67 56,0.008493,"89,302",24.57,0.00492,"93,543",27.8 57,0.009116,"88,544",23.78,0.005266,"93,083",26.93 58,0.00969,"87,736",22.99,0.00563,"92,592",26.07 59,0.010253,"86,886",22.21,0.006028,"92,071",25.22 60,0.010872,"85,995",21.44,0.006479,"91,516",24.37 61,0.011591,"85,060",20.67,0.007001,"90,923",23.52 62,0.012403,"84,075",19.9,0.007602,"90,287",22.68 63,0.013325,"83,032",19.15,0.008294,"89,600",21.85 64,0.01437,"81,925",18.4,0.009082,"88,857",21.03 65,0.015553,"80,748",17.66,0.00999,"88,050",20.22 66,0.016878,"79,492",16.93,0.011005,"87,171",19.42 67,0.018348,"78,151",16.21,0.012097,"86,211",18.63 68,0.019969,"76,717",15.51,0.013261,"85,168",17.85 69,0.021766,"75,185",14.81,0.014529,"84,039",17.09 70,0.02384,"73,548",14.13,0.015991,"82,818",16.33 71,0.026162,"71,795",13.47,0.017662,"81,494",15.59 72,0.028625,"69,917",12.81,0.019486,"80,054",14.86 73,0.031204,"67,915",12.18,0.021467,"78,494",14.14 74,0.033997,"65,796",11.55,0.023658,"76,809",13.44 75,0.0372,"63,559",10.94,0.026223,"74,992",12.76 76,0.040898,"61,195",10.34,0.029159,"73,026",12.09 77,0.04504,"58,692",9.76,0.032331,"70,896",11.44 78,0.049664,"56,048",9.2,0.035725,"68,604",10.8 79,0.054844,"53,265",8.66,0.039469,"66,153",10.18 80,0.060801,"50,344",8.13,0.043828,"63,542",9.58 81,0.067509,"47,283",7.62,0.048896,"60,757",9 82,0.074779,"44,091",7.14,0.054577,"57,786",8.43 83,0.082589,"40,794",6.68,0.060909,"54,633",7.89 84,0.091135,"37,424",6.23,0.068019,"51,305",7.37 85,0.10068,"34,014",5.81,0.076054,"47,815",6.87 86,0.111444,"30,589",5.4,0.085148,"44,179",6.4 87,0.123571,"27,180",5.02,0.095395,"40,417",5.94 88,0.137126,"23,822",4.65,0.106857,"36,561",5.52 89,0.152092,"20,555",4.31,0.119557,"32,655",5.12 90,0.168426,"17,429",4,0.133502,"28,751",4.75 91,0.186063,"14,493",3.7,0.148685,"24,912",4.4 92,0.204925,"11,797",3.44,0.165088,"21,208",4.08 93,0.224931,"9,379",3.19,0.182685,"17,707",3.79 94,0.245995,"7,270",2.97,0.201442,"14,472",3.53 95,0.266884,"5,481",2.78,0.220406,"11,557",3.29 96,0.287218,"4,018",2.61,0.239273,"9,010",3.08 97,0.306593,"2,864",2.46,0.257714,"6,854",2.89 98,0.324599,"1,986",2.33,0.275376,"5,088",2.72 99,0.340829,"1,341",2.21,0.291899,"3,687",2.56 100,0.35787,884,2.09,0.309413,"2,610",2.41 101,0.375764,568,1.98,0.327978,"1,803",2.27 102,0.394552,354,1.88,0.347656,"1,211",2.13 103,0.41428,215,1.77,0.368516,790,2 104,0.434993,126,1.68,0.390627,499,1.87 105,0.456743,71,1.58,0.414064,304,1.75 106,0.47958,39,1.49,0.438908,178,1.64 107,0.503559,20,1.4,0.465243,100,1.53 108,0.528737,10,1.32,0.493157,53,1.43 109,0.555174,5,1.24,0.522747,27,1.33 110,0.582933,2,1.16,0.554111,13,1.23 111,0.61208,1,1.09,0.587358,6,1.14 112,0.642683,0,1.02,0.622599,2,1.06 113,0.674818,0,0.95,0.659955,1,0.98 114,0.708559,0,0.89,0.699553,0,0.9 115,0.743986,0,0.82,0.741526,0,0.83 116,0.781186,0,0.76,0.781186,0,0.76 117,0.820245,0,0.71,0.820245,0,0.71 118,0.861257,0,0.65,0.861257,0,0.65 119,0.90432,0,0.6,0.90432,0,0.6 -------------------------------------------------------------------------------- /Students/Fiona/PS1/PS1_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \lstset{frame=single, 19 | language=Python, 20 | showstringspaces=false, 21 | columns=flexible, 22 | basicstyle={\small\ttfamily}, 23 | numbers=none, 24 | breaklines=true, 25 | breakatwhitespace=true 26 | tabsize=3 27 | } 28 | \usepackage{amsmath} 29 | \usepackage{amssymb} 30 | \usepackage{amsthm} 31 | \usepackage{harvard} 32 | \usepackage{setspace} 33 | \usepackage{float,color} 34 | \usepackage[pdftex]{graphicx} 35 | \usepackage{hyperref} 36 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 37 | \theoremstyle{definition} 38 | \newtheorem{theorem}{Theorem} 39 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 40 | \newtheorem{algorithm}[theorem]{Algorithm} 41 | \newtheorem{axiom}[theorem]{Axiom} 42 | \newtheorem{case}[theorem]{Case} 43 | \newtheorem{claim}[theorem]{Claim} 44 | \newtheorem{conclusion}[theorem]{Conclusion} 45 | \newtheorem{condition}[theorem]{Condition} 46 | \newtheorem{conjecture}[theorem]{Conjecture} 47 | \newtheorem{corollary}[theorem]{Corollary} 48 | \newtheorem{criterion}[theorem]{Criterion} 49 | \newtheorem{definition}[theorem]{Definition} 50 | \newtheorem{derivation}{Derivation} % Number derivations on their own 51 | \newtheorem{example}[theorem]{Example} 52 | \newtheorem{exercise}[theorem]{Exercise} 53 | \newtheorem{lemma}[theorem]{Lemma} 54 | \newtheorem{notation}[theorem]{Notation} 55 | \newtheorem{problem}[theorem]{Problem} 56 | \newtheorem{proposition}{Proposition} % Number propositions on their own 57 | \newtheorem{remark}[theorem]{Remark} 58 | \newtheorem{solution}[theorem]{Solution} 59 | \newtheorem{summary}[theorem]{Summary} 60 | %\numberwithin{equation}{section} 61 | \bibliographystyle{aer} 62 | \newcommand\ve{\varepsilon} 63 | \newcommand\boldline{\arrayrulewidth{1pt}\hline} 64 | 65 | 66 | \begin{document} 67 | 68 | \begin{flushleft} 69 | \textbf{\large{Problem Set \#1}} \\ 70 | MACS 40000, Dr. Evans \\ 71 | Fiona Fan 72 | \end{flushleft} 73 | 74 | \vspace{5mm} 75 | 76 | \noindent\textbf{Problem 1} 77 | 78 | \textbf{Part (a).} The Lagrangian is: 79 | \begin{equation*} 80 | \underset{c_{1,t}, c_{2,t+1}}{max} 81 | L= (1-\beta)ln(c_{1,t})+\beta ln(c_{2,t+1})-\lambda (p_t c_{1,t}+p_{t+1} c_{2,t+1}-p_t e_1-p_{t+1} e_2) 82 | \end{equation*} 83 | 84 | To satisfy first order condition: 85 | \begin{equation*} 86 | \frac{\partial L}{\partial c_{1,t}} = \frac{1-\beta}{c_{1,t}}-\lambda p_t = 0 87 | \end{equation*} 88 | \begin{equation} \label{c1foc} 89 | \Rightarrow \lambda = \frac{1-\beta}{c_{1,t} p_t} 90 | \end{equation} 91 | \begin{equation*} 92 | \frac{\partial L}{\partial c_{2,t+1}} = \frac{\beta}{c_{2,t+1}}-\lambda p_{t+1} = 0 93 | \end{equation*} 94 | \begin{equation} \label{c2foc} 95 | \Rightarrow \lambda = \frac{\beta}{c_{2,t+1} p_{t+1}} 96 | \end{equation} 97 | 98 | from \eqref{c1foc} and \eqref{c2foc} we can get the Euler equation: 99 | \begin{equation} \label{euler} 100 | c_{2,t+1}=\frac{\beta p_t}{(1-\beta) p_{t+1}} c_{1,t} 101 | \end{equation} 102 | 103 | To satisfy complementary slackness condition: 104 | \begin{equation*} 105 | \lambda (p_t c_{1,t}+p_{t+1} c_{2,t+1}-p_t e_1-p_{t+1} e_2) = 0 106 | \end {equation*} 107 | However, here $\lambda \neq 0$ because $\beta \neq 1$ and $c_{1,t} \neq 0$. Thus, 108 | \begin{equation} \label{constraint} 109 | p_t c_{1,t}+p_{t+1} c_{2,t+1}-p_t e_1-p_{t+1} e_2 = 0 110 | \end {equation} 111 | Substituting \eqref{euler} into \eqref{constraint} 112 | \begin{equation} \label{c1a} 113 | \Rightarrow c_{1,t}^*=\frac{(p_t e_1+p_{t+1} e_2)(1-\beta)}{p_t} 114 | \end {equation} 115 | \begin{equation} \label{c2a} 116 | \Rightarrow c_{2,t+1}^*=\frac{(p_t e_1+p_{t+1} e_2) \beta}{p_{t+1}} 117 | \end {equation} 118 | 119 | \textbf{Part (b).} The Lagrangian is: 120 | \begin{equation*} 121 | \underset{c_{2,1}}{max} 122 | L= \beta ln(c_{2,1})-\lambda (p_1 c_{2,1} - p_1 e_2) 123 | \end{equation*} 124 | 125 | To satisfy first order condition: 126 | \begin{equation*} 127 | \frac{\partial L}{\partial c_{2,1}} = \frac{\beta}{c_{2,1}}-\lambda p1 = 0 128 | \end{equation*} 129 | To satisfy complementary slackness condition: 130 | \begin{equation*} 131 | \lambda (p_1 c_{2,1}-p_1 e_2) = 0 132 | \end {equation*} 133 | However, here $\lambda \neq 0$ because $\beta \neq 1$ and $c_{2,1} \neq 0$. Thus, 134 | \begin{equation*} 135 | \Rightarrow c_{2,1}^*=\frac{p_1 e_2}{p_1} = e_2 136 | \end{equation*} 137 | 138 | \textbf{Part (c).} Plugging our answer in part (b) into the CE budget constraint we have: 139 | 140 | \begin{align*} 141 | c_{1,1}^*+c_{2,1}^*=e_1+e_2\\ 142 | c_{1,1}^*+e_2=e_1+e_2\\ 143 | \Rightarrow c_{1,1}^*=e_1 144 | \end{align*} 145 | Here, both the young and old consume all their repective endowments. There is no inter-generational exchange happening. These answers are different from the answers in part (a). 146 | \begin{equation*} 147 | \{c_{1,t},c_{2,t}\}_{t=1}^\infty = \{e_1,e_2\} 148 | \end{equation*} 149 | Since there is no inter-generational exchange happening, the prices can be arbitrary. 150 | 151 | \end{document} 152 | \begin{equation*} 153 | \end {equation*} 154 | -------------------------------------------------------------------------------- /Students/Sophia/ps4/Households.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | 7 | def MU_c_stitch(cvec, sigma, graph = False): 8 | epsilon = 1e-4 9 | muc = cvec ** (-sigma) 10 | m1 = (-sigma) * epsilon ** (-sigma - 1) 11 | m2 = epsilon ** (-sigma) - m1 * epsilon 12 | c_cnstr = cvec < epsilon 13 | muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 14 | 15 | if graph: 16 | # Create directory if images directory does not already exist 17 | cur_path = os.path.split(os.path.abspath(__file__))[0] 18 | output_fldr = "images" 19 | output_dir = os.path.join(cur_path, output_fldr) 20 | if not os.access(output_dir, os.F_OK): 21 | os.makedirs(output_dir) 22 | 23 | # Plot steady-state consumption and savings distributions 24 | cvec_CRRA = np.linspace(epsilon / 2, epsilon * 3, 1000) 25 | MU_CRRA = cvec_CRRA ** (-sigma) 26 | cvec_stitch = np.linspace(-0.0001, epsilon, 500) 27 | MU_stitch = m1 * cvec_stitch + m2 28 | fig, ax = plt.subplots() 29 | plt.plot(cvec_CRRA, MU_CRRA, ls='solid', label='$u\'(c)$: CRRA') 30 | plt.plot(cvec_stitch, MU_stitch, ls='dashed', color='red', 31 | label='$g\'(c)$: stitched') 32 | # for the minor ticks, use no labels; default NullFormatter 33 | minorLocator = MultipleLocator(1) 34 | ax.xaxis.set_minor_locator(minorLocator) 35 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 36 | plt.title('Marginal utility of consumption with stitched function', fontsize=15) 37 | plt.xlabel(r'Consumption $c$') 38 | plt.ylabel(r'Marginal utility $u\'(c)$') 39 | plt.xlim((-0.0001, epsilon * 3)) 40 | plt.legend(loc='upper right') 41 | output_path = os.path.join(output_dir, "MU_c_stitched") 42 | plt.savefig(output_path) 43 | plt.close() 44 | 45 | return muc 46 | 47 | cvec = np.array([-0.01, -0.004, 0.5, 2.6]) 48 | sigma = 2.2 49 | print(MU_c_stitch(cvec, sigma, graph = True)) 50 | 51 | def MDU_n_stitch(nvec, ltide, b, upsilon, graph = False): 52 | 53 | epsilon_lb = 1e-6 54 | epsilon_ub = ltilde - epsilon_lb 55 | 56 | mdun = ((b / ltilde) * ((nvec / ltilde) ** (upsilon - 1)) * (1 - ((nvec / ltilde) ** upsilon)) **\ 57 | ((1 - upsilon) / upsilon)) 58 | 59 | m1 = (b * (ltilde ** (-upsilon)) * (upsilon - 1) * (epsilon_lb ** (upsilon - 2)) * \ 60 | ((1 - ((epsilon_lb / ltilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 61 | (1 + ((epsilon_lb / ltilde) ** upsilon) * ((1 - ((epsilon_lb / ltilde) ** upsilon)) ** (-1)))) 62 | m2 = ((b / ltilde) * ((epsilon_lb / ltilde) ** (upsilon - 1)) * \ 63 | ((1 - ((epsilon_lb / ltilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (m1 * epsilon_lb)) 64 | 65 | q1 = (b * (ltilde ** (-upsilon)) * (upsilon - 1) * (epsilon_ub ** (upsilon - 2)) * \ 66 | ((1 - ((epsilon_ub / ltilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 67 | (1 + ((epsilon_ub / ltilde) ** upsilon) * ((1 - ((epsilon_ub / ltilde) ** upsilon)) ** (-1)))) 68 | 69 | q2 = ((b / ltilde) * ((epsilon_ub / ltilde) ** (upsilon - 1)) * \ 70 | ((1 - ((epsilon_ub / ltilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (q1 * epsilon_ub)) 71 | 72 | nl_cstr = nvec < epsilon_lb 73 | nu_cstr = nvec > epsilon_ub 74 | 75 | mdun[nl_cstr] = m1 * nvec[nl_cstr] + m2 76 | mdun[nu_cstr] = q1 * nvec[nu_cstr] + q2 77 | 78 | if graph: 79 | cur_path = os.path.split(os.path.abspath(__file__))[0] 80 | output_fldr = "images" 81 | output_dir = os.path.join(cur_path, output_fldr) 82 | if not os.access(output_dir, os.F_OK): 83 | os.makedirs(output_dir) 84 | 85 | # Plot steady-state consumption and savings distributions 86 | nvec_ellip = np.linspace(epsilon_lb / 2, epsilon_ub + 87 | ((ltilde - epsilon_ub) / 5), 1000) 88 | MU_ellip = ((b / ltilde) * ((nvec_ellip / ltilde) ** (upsilon - 1)) * \ 89 | ((1 - ((nvec_ellip / ltilde) ** upsilon)) ** ((1 - upsilon) / upsilon))) 90 | n_stitch_low = np.linspace(-0.1, epsilon_lb, 500) 91 | MU_stitch_low = m1 * n_stitch_low + m2 92 | n_stitch_high = np.linspace(epsilon_ub, ltilde + 0.00005, 500) 93 | MU_stitch_high = q1 * n_stitch_high + q2 94 | 95 | fig, ax = plt.subplots() 96 | plt.plot(nvec_ellip, MU_ellip, ls='solid', color='black', label='$v\'(n)$: Elliptical') 97 | plt.plot(n_stitch_low, MU_stitch_low, ls='dashed', color='red', label='$g\'(n)$: low stitched') 98 | plt.plot(n_stitch_high, MU_stitch_high, ls='dotted', color='blue', label='$g\'(n)$: high stitched') 99 | # for the minor ticks, use no labels; default NullFormatter 100 | minorLocator = MultipleLocator(1) 101 | ax.xaxis.set_minor_locator(minorLocator) 102 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 103 | plt.title('Marginal disutility of labor with stitched function', fontsize=15) 104 | plt.xlabel(r'Labor $n$') 105 | plt.ylabel(r'Marginal disutility $v\'(n)$') 106 | plt.xlim((-0.1, ltilde + 0.00005)) 107 | # plt.ylim((-1.0, 1.15 * (b_ss.max()))) 108 | plt.legend(loc='upper left') 109 | output_path = os.path.join(output_dir, "MU_n_stitched") 110 | plt.savefig(output_path) 111 | plt.close() 112 | 113 | return mdun 114 | 115 | nvec = np.array([-0.013, -0.002, 0.42, 1.007, 1.011]) 116 | ltilde = 1.0 117 | b_ellip = 0.5 118 | upsilon = 1.5 119 | print(MDU_n_stitch(nvec, ltilde, b_ellip, upsilon, graph = True)) 120 | -------------------------------------------------------------------------------- /Students/Fiona/PS6/script.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import matplotlib 6 | from matplotlib import cm 7 | import math 8 | import os 9 | import SS as ss 10 | import TPI as tpi 11 | 12 | 13 | 14 | df_main = pd.read_stata('p13i6.dta') 15 | df_summ = pd.read_stata('rscfp2013.dta') 16 | df = pd.concat([df_main, df_summ], axis=1) 17 | ID = np.arange(1, len(df)+1) 18 | df ['ID'] = ID 19 | df = df[['ID','X5804', 'X5805','X5809', 'X5810', 'X5814', 'X5815', 'X8022', 'networth', 'wgt']] 20 | df.rename(columns={'X5804': 'b1', 'X5805': 't1','X5809':'b2', 'X5810':'t2', 'X5814':'b3', 'X5815':'t3', 'X8022':'age'}, inplace=True) 21 | # print(df.shape) 22 | # print (df['b2'].sum()) 23 | 24 | #data cleaning 25 | df.loc[df.age<0, 'age'] = 2013+df.loc[df.age<0, 'age'] 26 | 27 | df.loc[df.t1<2011, 'b1'] = 0 28 | df.loc[df.t2<2011, 'b2'] = 0 29 | df.loc[df.t3<2011, 'b3'] = 0 30 | df['age_b1']=df['age']-(2013-df['t1']) 31 | df['age_b2']=df['age']-(2013-df['t2']) 32 | df['age_b3']=df['age']-(2013-df['t3']) 33 | df = df[((df[['age']].T >=21) & (df[['age']].T <=100) ).any()] 34 | df = df[((df[['age_b1']].T >=21) & (df[['age_b1']].T <=100) ).any()] 35 | 36 | 37 | #adjust for inflation 38 | df[df.t1 == 2011].b1 *= 0.9652 39 | df[df.t2 == 2011].b2 *= 0.9652 40 | df[df.t3 == 2011].b3 *= 0.9652 41 | df[df.t1 == 2012].b1 *= 0.9854 42 | df[df.t2 == 2012].b2 *= 0.9854 43 | df[df.t3 == 2012].b3 *= 0.9854 44 | 45 | total= np.sum(df.b1 * df.wgt) / np.sum(df[df.b1!=0].wgt) * len(df[df.b1!=0]) + \ 46 | np.sum(df.b2 * df.wgt) / np.sum(df[df.b2!=0].wgt) * len(df[df.b2!=0]) + \ 47 | np.sum(df.b3 * df.wgt) / np.sum(df[df.b3!=0].wgt) * len(df[df.b3!=0]) 48 | 49 | print (total) 50 | 51 | 52 | def get_bq_tot (df, start_age, end_age, graph=True): 53 | bq_tot = dict(zip(list(range(start_age, end_age + 1)), [0] * (end_age - start_age + 1))) 54 | bq_pct = dict(zip(list(range(start_age, end_age + 1)), [0] * (end_age - start_age + 1))) 55 | for age in range (start_age, end_age + 1): 56 | 57 | sum_age_b1 = np.sum(df[df.age_b1 == age].b1 * df[df.age_b1 == age].wgt)/ np.sum(df[df.age_b1 == age].wgt) * \ 58 | len(df[df.age_b1 == age]) 59 | # print (f'sum_age_b1:{sum_age_b1}') 60 | sum_age_b2 = np.sum(df[df.age_b2 == age].b2 * df[df.age_b2 == age].wgt) / np.sum(df[df.age_b2 == age].wgt) * \ 61 | len(df[df.age_b2 == age]) 62 | # print(f'sum_age_b2:{sum_age_b2}') 63 | sum_age_b3 = np.sum(df[df.age_b3 == age].b3 * df[df.age_b3 == age].wgt) / np.sum(df[df.age_b3 == age].wgt) * \ 64 | len(df[df.age_b3 == age]) 65 | # print(f'sum_age_b3:{sum_age_b3}') 66 | if math.isnan(sum_age_b1): sum_age_b1 = 0 67 | if math.isnan(sum_age_b2): sum_age_b2 = 0 68 | if math.isnan(sum_age_b3): sum_age_b3 = 0 69 | pct_age = (sum_age_b1 + sum_age_b2 + sum_age_b3) / total 70 | 71 | # bq_tot[age] = pct_age 72 | bq_tot[age] = sum_age_b1 + sum_age_b2 + sum_age_b3 73 | # print (f'bq_tot[{age}]: {bq_tot[age]}') 74 | bq_pct[age] = pct_age 75 | # print(f'bq_pct[{age}]: {bq_pct[age]}') 76 | if graph: 77 | cur_path = os.path.split(os.path.abspath(__file__))[0] 78 | output_fldr = "images" 79 | output_dir = os.path.join(cur_path, output_fldr) 80 | if not os.access(output_dir, os.F_OK): 81 | os.makedirs(output_dir) 82 | plt.plot(bq_pct.keys(), bq_pct.values(), 'go--', label='bequest distribution across ages') 83 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 84 | plt.title('Distribution of Bequest across Ages', fontsize=20) 85 | plt.xlabel('age') 86 | plt.ylabel('pct') 87 | # plt.legend() 88 | # plt.show() 89 | output_path = os.path.join(output_dir, 'distribution') 90 | plt.savefig(output_path) 91 | plt.close() 92 | 93 | # print(bq_tot.values()) 94 | # print(list(bq_tot.values())) 95 | return list(bq_pct.values()) 96 | 97 | 98 | bq_tot_all= get_bq_tot(df, 21, 100, graph=True) 99 | 100 | # print (df.networth.quantile(.25)[1]) 101 | cut_25, cut_50, cut_75, cut_100=df.networth.quantile([.25,0.5,0.75,1]).values 102 | # print (cutoffs.loc[0.25]) 103 | df_25 = df[df.networth < cut_25] 104 | df_50 = df[((df[['networth']].T >=cut_25) & (df[['networth']].T =cut_50) & (df[['networth']].T =cut_75) & (df[['networth']].T epsilon_ub 127 | # 128 | # mun = ((b / l_tilde) * ((nvec / l_tilde) ** (upsilon - 1)) * (1 - ((nvec / l_tilde) ** upsilon)) **\ 129 | # ((1 - upsilon) / upsilon)) 130 | # m1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_lb ** (upsilon - 2)) * \ 131 | # ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 132 | # (1 + ((epsilon_lb / l_tilde) ** upsilon) * ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** (-1)))) 133 | # m2 = ((b / l_tilde) * ((epsilon_lb / l_tilde) ** (upsilon - 1)) * \ 134 | # ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (m1 * epsilon_lb)) 135 | # q1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_ub ** (upsilon - 2)) * \ 136 | # ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 137 | # (1 + ((epsilon_ub / l_tilde) ** upsilon) * ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** (-1)))) 138 | # q2 = ((b / l_tilde) * ((epsilon_ub / l_tilde) ** (upsilon - 1)) * \ 139 | # ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (q1 * epsilon_ub)) 140 | # mun[nl_cstr] = m1 * nvec[nl_cstr] + m2 141 | # mun[nu_cstr] = q1 * nvec[nu_cstr] + q2 142 | # return mun 143 | 144 | class cstError (Exception): 145 | pass 146 | 147 | -------------------------------------------------------------------------------- /Students/Fiona/PS3/SS.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET 3 4 | Solving steady state for S-period model 5 | Author: Fiona Fan 6 | ''' 7 | import numpy as np 8 | import time 9 | import scipy.optimize as opt 10 | import matplotlib.pyplot as plt 11 | from matplotlib.ticker import MultipleLocator 12 | 13 | 14 | 15 | def feasible(f_params, bvec_guess): 16 | b_cnstr=np.zeros(bvec_guess.shape,dtype=bool) 17 | nvec, A, alpha, delta=f_params 18 | K,K_cnstr=get_K(bvec_guess) 19 | L=get_L(nvec) 20 | r=get_r((A, alpha, delta),L,K) 21 | w=get_w((A, alpha),L,K) 22 | c_vec,c_cnstr=get_cvec(r,w,bvec_guess,nvec) 23 | 24 | b_cnstr[0]=c_cnstr[0] 25 | b_cnstr[-1]=c_cnstr[-1] 26 | for k in range(1,len(c_cnstr)-1): 27 | b_cnstr[k]=c_cnstr[k] 28 | b_cnstr[k-1]=b_cnstr[k] 29 | return b_cnstr, c_cnstr, K_cnstr 30 | 31 | def get_r(params,K,L): 32 | A, alpha, delta=params 33 | return alpha*A*((L/K)**(1-alpha))-delta 34 | def get_w(params,K,L): 35 | A, alpha = params 36 | return (1-alpha)*A*((K/L)**alpha) 37 | def get_cvec(r, w, bvec, nvec): 38 | b=np.append([0],bvec) 39 | b1=np.append(bvec,[0]) 40 | # print(f"nvec shape is: {nvec.shape}") 41 | c_vec = (1 + r) * b + w * nvec - b1 42 | c_cnstr = c_vec <= 0 43 | # print(f"cvec shape is: {c_vec.shape}") 44 | return c_vec, c_cnstr 45 | 46 | 47 | def get_K(b_vec): 48 | return sum(b_vec), sum(b_vec)<=0 49 | def get_L(nvec): 50 | return sum(nvec) 51 | 52 | def get_Y(params, K, L): 53 | 54 | A, alpha = params 55 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 56 | 57 | return Y 58 | 59 | def get_C(cvec): 60 | 61 | if cvec.ndim == 1: 62 | C = cvec.sum() 63 | elif cvec.ndim == 2: 64 | C = cvec.sum(axis=0) 65 | return C 66 | 67 | def zero_func(vec,*args): 68 | beta, sigma, nvec, L, A, alpha, delta=args 69 | K= get_K(vec)[0] 70 | L=get_L(nvec) 71 | r=get_r((A, alpha, delta),K,L) 72 | w=get_w((A, alpha),K,L) 73 | cvec,c_cnstr=get_cvec(r, w, vec, nvec) 74 | MU_c=get_MUc(cvec,sigma) 75 | errors=beta*(1+r)*MU_c[1:]-MU_c[:-1] 76 | return errors 77 | 78 | def get_SS(params, bvec_guess, SS_graphs): 79 | start_time = time.clock() 80 | beta, sigma, nvec, L, A, alpha, delta, SS_tol = params 81 | f_params = (nvec, A, alpha, delta) 82 | b1_cnstr, c1_cnstr, K1_cnstr = feasible(f_params, bvec_guess) 83 | try: 84 | if b1_cnstr.max() or c1_cnstr.max() or K1_cnstr.max(): 85 | raise cstError 86 | 87 | else: 88 | # errors=zero_func(bvec_guess,beta, sigma, nvec, L, A, alpha, delta) 89 | b = opt.root(zero_func, bvec_guess,args=(beta, sigma, nvec, L, A, alpha, delta), tol=SS_tol) 90 | except cstError: 91 | print ('Did not pass the feasible test') 92 | if b.success: 93 | b_ss = b.x 94 | # iterations=b.nit 95 | 96 | K_ss, K_cnstr = get_K(b_ss) 97 | L=get_L(nvec) 98 | w_ss = get_w((A, alpha),K_ss,L) 99 | r_ss = get_r((A, alpha, delta),K_ss, L) 100 | Y_ss = get_Y( (A, alpha),K_ss, L) 101 | c_ss, c_cnstr = get_cvec(r_ss, w_ss, b_ss, nvec) 102 | EulErr_ss = get_b_errors((beta, sigma), r_ss, c_ss, c_cnstr) 103 | C_ss=get_C(c_ss) 104 | RCerr_ss = Y_ss - C_ss - delta * K_ss 105 | 106 | ss_time = time.clock() - start_time 107 | ss_output={'b_ss': b_ss, 'c_ss': c_ss, 'w_ss': w_ss, 'r_ss': r_ss, 108 | 'K_ss': K_ss, 'Y_ss': Y_ss, 'C_ss': C_ss, 109 | 'EulErr_ss': EulErr_ss, 'RCerr_ss': RCerr_ss, 110 | 'ss_time': ss_time} 111 | 112 | print('\n Savings: \t\t\t {} \n Capital and Labor: \t\t {} \n Wage and Interest rate: \t {} \n Consumption: \t\t\t {}'.format( 113 | b_ss, np.array([K_ss, L]), np.array([w_ss, r_ss]), c_ss)) 114 | 115 | print('Euler errors: ', EulErr_ss) 116 | print('Resource Constraint error: ', RCerr_ss) 117 | print('Time needed: ', ss_time) 118 | # print ('It took {iterations} iterations to get the solution.') 119 | if SS_graphs: 120 | age = np.arange(1, 81) 121 | fig, ax = plt.subplots() 122 | plt.plot(age, c_ss, marker='D', label='Consumption') 123 | plt.plot(age, np.append([0], b_ss), marker='D', label='Savings') 124 | 125 | minorLocator = MultipleLocator(1) 126 | ax.xaxis.set_minor_locator(minorLocator) 127 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 128 | plt.title('Steady-state consumption and savings') 129 | plt.xlabel('Age') 130 | plt.ylabel('Consumption units') 131 | plt.legend() 132 | plt.show() 133 | 134 | 135 | return ss_output 136 | 137 | def EulerSys(bvec, params): 138 | 139 | beta, sigma, nvec, L, A, alpha, delta = params 140 | K, K_cnstr = get_K(bvec) 141 | try: 142 | if K_cnstr: 143 | raise cstError 144 | 145 | 146 | else: 147 | r_params =np.array( [A, alpha, delta]) 148 | r = get_r(r_params, K, L) 149 | w_params = np.array([A, alpha]) 150 | w = get_w(w_params, K, L) 151 | cvec, c_cnstr = get_cvec(r, w, bvec, nvec) 152 | b_err_params = np.array([beta, sigma]) 153 | b_err_vec = get_b_errors(b_err_params, r, cvec, c_cnstr) 154 | except cstError: 155 | print ('Did not pass the feasible test') 156 | 157 | return b_err_vec 158 | 159 | def get_b_errors(params, r, cvec, c_cnstr): 160 | beta, sigma = params 161 | # try: 162 | # if c_cnstr.max(): 163 | # raise cstError 164 | # 165 | # else: 166 | MU_c12=get_MUc(cvec[:-1],sigma) 167 | MU_c23=get_MUc(cvec[1:],sigma) 168 | b_errors = (beta * (1 + r) * MU_c23) - MU_c12 169 | # except cstError: 170 | # print ('Did not pass the feasible test') 171 | return b_errors 172 | 173 | 174 | 175 | def get_MUc(cvec,sigma): 176 | epsilon=0.0001 177 | cvec_neg=cvec<=0 178 | MU_c=np.zeros_like(cvec) 179 | MU_c[cvec_neg]=epsilon**(-sigma) 180 | MU_c[~cvec_neg]=cvec[~cvec_neg]**(-sigma) 181 | return MU_c 182 | 183 | 184 | class cstError (Exception): 185 | pass 186 | 187 | -------------------------------------------------------------------------------- /Students/Fiona/PS3/PS3_Fiona.tex: -------------------------------------------------------------------------------- 1 | \documentclass[letterpaper,12pt]{article} 2 | \usepackage{array} 3 | \usepackage{threeparttable} 4 | \usepackage{geometry} 5 | \geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin=1.25in,rmargin=1.25in} 6 | \usepackage{fancyhdr,lastpage} 7 | \pagestyle{fancy} 8 | \lhead{} 9 | \chead{} 10 | \rhead{} 11 | \lfoot{} 12 | \cfoot{} 13 | \rfoot{\footnotesize\textsl{Page \thepage\ of \pageref{LastPage}}} 14 | \renewcommand\headrulewidth{0pt} 15 | \renewcommand\footrulewidth{0pt} 16 | \usepackage[format=hang,font=normalsize,labelfont=bf]{caption} 17 | \usepackage{listings} 18 | \usepackage{booktabs} 19 | \lstset{frame=single, 20 | language=Python, 21 | showstringspaces=false, 22 | columns=flexible, 23 | basicstyle={\small\ttfamily}, 24 | numbers=none, 25 | breaklines=true, 26 | breakatwhitespace=true 27 | tabsize=3 28 | } 29 | \usepackage{amsmath} 30 | \usepackage{amssymb} 31 | \usepackage{amsthm} 32 | \usepackage{harvard} 33 | \usepackage{setspace} 34 | \usepackage{float,color} 35 | \usepackage[pdftex]{graphicx} 36 | \usepackage{hyperref} 37 | \usepackage{pgfplotstable} 38 | \hypersetup{colorlinks,linkcolor=red,urlcolor=blue} 39 | \theoremstyle{definition} 40 | \newtheorem{theorem}{Theorem} 41 | \newtheorem{acknowledgement}[theorem]{Acknowledgement} 42 | \newtheorem{algorithm}[theorem]{Algorithm} 43 | \newtheorem{axiom}[theorem]{Axiom} 44 | \newtheorem{case}[theorem]{Case} 45 | \newtheorem{claim}[theorem]{Claim} 46 | \newtheorem{conclusion}[theorem]{Conclusion} 47 | \newtheorem{condition}[theorem]{Condition} 48 | \newtheorem{conjecture}[theorem]{Conjecture} 49 | \newtheorem{corollary}[theorem]{Corollary} 50 | \newtheorem{criterion}[theorem]{Criterion} 51 | \newtheorem{definition}[theorem]{Definition} 52 | \newtheorem{derivation}{Derivation} % Number derivations on their own 53 | \newtheorem{example}[theorem]{Example} 54 | \newtheorem{exercise}[theorem]{Exercise} 55 | \newtheorem{lemma}[theorem]{Lemma} 56 | \newtheorem{notation}[theorem]{Notation} 57 | \newtheorem{problem}[theorem]{Problem} 58 | \newtheorem{proposition}{Proposition} % Number propositions on their own 59 | \newtheorem{remark}[theorem]{Remark} 60 | \newtheorem{solution}[theorem]{Solution} 61 | \newtheorem{summary}[theorem]{Summary} 62 | %\numberwithin{equation}{section} 63 | \bibliographystyle{aer} 64 | %\newcommand\ve{\varepsilon} 65 | %\newcommand\boldline{\arrayrulewidth{1pt}\hline} 66 | 67 | 68 | \begin{document} 69 | 70 | \begin{flushleft} 71 | \textbf{\large{Problem Set \#[3]}} \\ 72 | MACS 40000, Dr. Evans \\ 73 | Fiona Fan 74 | \end{flushleft} 75 | 76 | \vspace{5mm} 77 | 78 | \noindent\textbf{Problem 1} 79 | \\ \textbf{Part (a).} The first period consumption, $c_1$ is negative, most possibly resulted from a excessively big $b_1$. 80 | \\ \textbf{Part (b).} No constraint is violated. 81 | \\ \textbf{Part (c).} No constraint is violated.\\ 82 | 83 | 84 | 85 | 86 | \noindent\textbf{Problem 2} \\ 87 | \textbf{Part (a).} Please see Column B and D of $problem2.csv$ for $\{{b_t}_{t=1}^{S}\}$ and $\{{c_t}_{t=1}^{S}\}$. $\bar{K}$ and $\bar{L}$ are 494.14 and 58.4, and $\bar{w}$ and $\bar{r}$ are 1.37 and 0.037 respectively. The computations took 0.046s and 0.083s. 88 | 89 | \textbf{Part (b).} Please see Figure \ref{Fig1}. 90 | 91 | \textbf{Part (c).} 92 | \par See the Column C and E of $problem2.csv$ and \ref{Fig2} for $\{{b_t}_{t=1}^{S}\}$ and $\{{c_t}_{t=1}^{S}\}$. $\bar{K}$ and $\bar{L}$ change 565.88 and 48 respectively, and $\bar{w}$ and $\bar{r}$ change to 1.54 and 0.02. For both, once the agents retire, they cut their savings to keep their consumption at a near constant level. For agents that retire earlier, they cut happens earlier. The maximum amount of saving for when $n=2/3$ is 15.29, and when $n=1/2$, then maximum is 16.45. On average before the cut the agents in $n=1/2$ case save more to reach that higher maximum. And on average teh agents in the $n=2/3$ case consume and save more because they have worked more and have more money. 93 | 94 | \textbf{Part (c).} 95 | \par Since $c_{s,t}=(1+r_t)b_{s,t}+w_t n_s-b_{s+1,t+1}$, there should be a lower bound for $b_{s,t}$ and an upper bound for $b_{s+1,t+1}$ to keep $c_{s,t}$ positive. 96 | 97 | \noindent\textbf{Problem 3}\\ 98 | \textbf{Part (a).} Please see Figure \ref{Fig3}, Figure \ref{Fig4} and Figure \ref{Fig5} for $\{{K_t}_{t=1}^{T+5}\}$, $\{{w_t}_{t=1}^{T+5}\}$ and $\{{r_t}_{t=1}^{T+5}\}$ respectively. 99 | 100 | \noindent\textbf{Part (b).} Please see Figure \ref{Fig6} for $\{{b_{15,t}}_{t=1}^{T+5}\}$. $b_{15,t}$ rises above $\bar{b_15}$ 220 times. The first time appears at period 2. 101 | 102 | \noindent\textbf{Part (c).} In period 219, the economy first gets to within 0.00001 of the steady state. After period 320, which is the last period, the economy is never again father than 0.00001 away from the steady state. That means within each agents' lifetime, K does not get within the threshold approximating $K_ss$. 103 | 104 | 105 | 106 | \begin{figure}[htb]\centering 107 | \captionsetup{width=4.0in} 108 | \caption{\textbf{Steady-State Distribution of Consumption and Savings by Age when $n=2/3$}} 109 | \label{Fig1} 110 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/n1.png}}} 111 | \end{figure} 112 | 113 | \begin{figure}[htb]\centering 114 | \captionsetup{width=4.0in} 115 | \caption{\textbf{Steady-State Distribution of Consumption and Savings by Age when $n=1/2$}} 116 | \label{Fig2} 117 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/n2.png}}} 118 | \end{figure} 119 | 120 | \begin{figure}[htb]\centering 121 | \captionsetup{width=4.0in} 122 | \caption{\textbf{$\{{K_t}_{t=1}^{T+5}\}$}} \label{Fig3} 123 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/Kpath.png}}} 124 | \end{figure} 125 | 126 | \begin{figure}[htb]\centering 127 | \captionsetup{width=4.0in} 128 | \caption{\textbf{$\{{w_t}_{t=1}^{T+5}\}$}} 129 | \label{Fig4} 130 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/wpath.png}}} 131 | \end{figure} 132 | 133 | \begin{figure}[htb]\centering 134 | \captionsetup{width=4.0in} 135 | \caption{\textbf{$\{{r_t}_{t=1}^{T+5}\}$}} 136 | \label{Fig5} 137 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/rpath.png}}} 138 | \end{figure} 139 | 140 | \begin{figure}[htb]\centering 141 | \captionsetup{width=4.0in} 142 | \caption{\textbf{$\{{b_{15,t}}_{t=1}^{T+5}\}$}} 143 | \label{Fig6} 144 | \fbox{\resizebox{4.0in}{3.0in}{\includegraphics{images/b15path.png}}} 145 | \end{figure} 146 | 147 | 148 | \end{document} 149 | 150 | -------------------------------------------------------------------------------- /Students/Fiona/PS6/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | 7 | 8 | 9 | ''' 10 | Stiching functions for U(c) and g(b) 11 | ''' 12 | def MU_c_stitch(cvec, sigma): 13 | epsilon = 1e-4 14 | c_cnstr = cvec < epsilon 15 | muc = cvec ** (-sigma) 16 | # print (f"cvec:{cvec.shape}") 17 | m1 = (-sigma) * epsilon ** (-sigma - 1) 18 | m2 = epsilon ** (-sigma) - m1 * epsilon 19 | muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 20 | 21 | return muc 22 | 23 | ''' 24 | Firm utilities: 25 | calculate wage and interest rate 26 | ''' 27 | 28 | def get_w(K, L, params): 29 | A, alpha = params 30 | w = (1 - alpha) * A * (K/L) **alpha 31 | 32 | return w 33 | 34 | def get_r(K, L, params): 35 | A, alpha, delta = params 36 | r = alpha * A * ((L/K) ** (1 - alpha)) - delta 37 | return r 38 | 39 | ''' 40 | Household utilities 41 | ''' 42 | # #Calculate the remaning consumptions in one's lifetime. 43 | 44 | 45 | def get_cvec_ss(r, w, bvec, nvec, bq_distr): 46 | #bvec=b2 ~ bS+1 47 | #cvec:c1 ~ cS+1 48 | #nvec:n1 ~ nS+1 49 | b=np.append([0],bvec[:-1]) 50 | b1=bvec 51 | 52 | bq = (1 + r) * bvec[-1] 53 | # print(f"bvec shape is: {bvec.shape}, b shape is: {b.shape}, bq {bq}, bq_distr {bq_distr.shape}, w {w}, nvec {nvec.shape}, r {r}") 54 | 55 | c_vec = (1 + r) * b + w * nvec - b1 + bq_distr * bq 56 | c_cnstr = c_vec <= 0 57 | # print(f"cvec shape is: {c_vec.shape}") 58 | return c_vec, c_cnstr 59 | 60 | # 61 | def get_cvec_tpi(rpath, wpath, bvec, nvec, bq, bq_distr): 62 | # bq_distr, beta = params 63 | #bvec=b1 ~ bS+1 64 | #cvec:c1 ~ cS 65 | #nvec:n1 ~ nS 66 | b=bvec[:-1] 67 | b1=bvec[1:] 68 | # print(f"bvec shape is: {bvec.shape}, b shape is: {b.shape}, bq {bq}, bq_distr {bq_distr.shape}, w {w}, nvec {nvec.shape}, r {r}") c_vec: {c_vec.shape}, 69 | # print (f'b: {b.shape}, rpath{rpath.shape}, wpath:{wpath.shape}, bq_distr{bq_distr.shape}, bq{bq.shape}, nvec{nvec.shape}') 70 | c_vec = (1 + rpath) * b + wpath * nvec - b1 + bq * bq_distr 71 | c_cnstr = c_vec <= 0 72 | # print(f"cvec shape is: {c_vec.shape}") 73 | return c_vec, c_cnstr 74 | 75 | 76 | ######## Euler Equations 77 | 78 | 79 | def EulerSys_ss(vec, *args): 80 | beta, sigma, nvec, A, alpha, delta, bq_distr, chi=args 81 | K= get_K(vec)[0] 82 | L=get_L(nvec) 83 | r=get_r(K,L, (A, alpha, delta)) 84 | w=get_w(K,L, (A, alpha)) 85 | # cvec:c1 ~ cS 86 | cvec,c_cnstr=get_cvec_ss(r, w, vec, nvec, bq_distr) 87 | errors=np.zeros(np.shape(vec)) 88 | # MU_c=MU_c_stitch(cvec,sigma) 89 | errors[:-1] = beta*(1+r)*MU_c_stitch(cvec[1:],sigma)-MU_c_stitch(cvec[:-1],sigma) 90 | errors[-1] = chi[-1] * vec[-1] ** (-sigma)- cvec[-1] ** (-sigma) 91 | return errors 92 | 93 | # def EulerSys_tpi(bvec, *args): 94 | # #bvec: 2 ~ S+1 95 | # beta, sigma, beg_wealth, nvec, rpath, wpath, bq_distr, chi, bq = args 96 | # #bvec2: 1 ~ S+1 97 | # bvec2 = np.append(beg_wealth, bvec) 98 | # #cvec: 1 ~ S 99 | # cvec, c_cnstr = get_cvec_tpi(rpath, wpath, nvec, bvec2, bq) 100 | # errors = np.zeros(np.shape(bvec)) 101 | # #errors: 1 ~ S 102 | # errors[:-1] = beta * (1 + rpath[1:]) * MU_c_stitch(cvec[1:], sigma) - MU_c_stitch(cvec[:-1], sigma) 103 | # errors[-1] = chi[-1] * bvec2[-1] ** (-sigma) - cvec[-1] ** (-sigma) 104 | # return errors 105 | 106 | def EulerSys_tpi(bvec, *args): 107 | beg_wealth, nvec, beta, sigma, wpath, rpath, BQpath, chi, bq_distr = args 108 | b = np.append(beg_wealth, bvec) 109 | # print (f'b: {b.shape}, BQ:{BQpath.shape}, chi:{chi.shape}, bq_distr:{bq_distr.shape}, bvec: {bvec.shape}',rpath.shape) 110 | # cvec = get_cvec_ss(rpath, wpath, bvec, nvec, bq_distr) 111 | cvec = (1 + rpath) * b[:-1] + wpath * nvec + bq_distr * BQpath - bvec 112 | muc = MU_c_stitch(cvec, sigma) 113 | errors = np.zeros(np.shape(cvec)) 114 | errors[:-1] = muc[:-1] - beta * (1 + rpath[1:]) * muc[1:] 115 | errors[-1] = chi[-1] * (b[-1]) ** (-sigma)- ((1 + rpath[-1]) * b[-2] + wpath[-1] * nvec[-1] + bq_distr[-1] * 116 | BQpath[-1] - b[-1]) ** (-sigma) 117 | 118 | return errors 119 | 120 | 121 | ######## Calculate aggregates 122 | 123 | #from s=1 to S 124 | def get_L(narr): # function for aggregate labor supply 125 | epsilon = 0.01 126 | a = epsilon / np.exp(1) 127 | b = 1 / epsilon 128 | if narr.ndim == 1: # This is the steady-state case 129 | L = narr.sum() 130 | L_cstr = L < epsilon 131 | if L_cstr: 132 | print('get_L() warning: Distribution of savings and/or ' + 133 | 'parameters created L < epsilon') 134 | # Force K >= eps by stitching a * exp(b * K) for K < eps 135 | L = a * np.exp(b * L) 136 | 137 | elif narr.ndim == 2: # This is the time path case 138 | L = narr.sum(axis=0) 139 | L_cstr = L < epsilon 140 | if L.min() < epsilon: 141 | print('get_L() warning: Aggregate capital constraint is ' + 142 | 'violated (L < epsilon) for some period in time ' + 143 | 'path.') 144 | L[L_cstr] = a * np.exp(b * L[L_cstr]) 145 | return L 146 | 147 | # from s=2 to S+1 148 | def get_K(barr): # function for aggregate capital supply 149 | epsilon = 0.01 150 | a = epsilon / np.exp(1) 151 | b = 1 / epsilon 152 | if barr.ndim == 1: # This is the steady-state case 153 | K = barr.sum() 154 | K_cstr = K < epsilon 155 | if K_cstr: 156 | print('get_K() warning: Distribution of savings and/or ' + 157 | 'parameters created K < epsilon') 158 | # Force K >= eps by stitching a * exp(b * K) for K < eps 159 | K = a * np.exp(b * K) 160 | 161 | elif barr.ndim == 2: # This is the time path case 162 | K = barr.sum(axis=0) 163 | K_cstr = K < epsilon 164 | if K.min() < epsilon: 165 | print('get_K() warning: Aggregate capital constraint is ' + 166 | 'violated (K < epsilon) for some period in time ' + 167 | 'path.') 168 | K[K_cstr] = a * np.exp(b * K[K_cstr]) 169 | 170 | return K, K_cstr 171 | 172 | def get_Y(K, L, params): # function for aggregate output 173 | A, alpha = params 174 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 175 | return Y 176 | 177 | def get_C(carr): 178 | if carr.ndim == 1: 179 | C = carr.sum() 180 | elif carr.ndim == 2: 181 | C = carr.sum(axis=0) 182 | 183 | return C 184 | -------------------------------------------------------------------------------- /Students/Fiona/PS6/SS.py: -------------------------------------------------------------------------------- 1 | ''' 2 | MACS 40000 Rick Evans 3 | PSET 6 4 | Solving steady state for S-period model 5 | Author: Fiona Fan 6 | ''' 7 | import numpy as np 8 | import time 9 | import scipy.optimize as opt 10 | import matplotlib.pyplot as plt 11 | from matplotlib.ticker import MultipleLocator 12 | import utils 13 | import os 14 | 15 | 16 | def feasible(f_params, bvec_guess): 17 | b_cnstr=np.zeros(bvec_guess.shape,dtype=bool) 18 | nvec, A, alpha, delta, bq_distr, beta=f_params 19 | K,K_cnstr=utils.get_K(bvec_guess) 20 | L=utils.get_L(nvec) 21 | r=utils.get_r(K,L,(A, alpha, delta)) 22 | w=utils.get_w(K,L,(A, alpha)) 23 | c_vec,c_cnstr=utils.get_cvec_ss(r, w, bvec_guess, nvec, bq_distr) 24 | b_cnstr[0]=c_cnstr[0] 25 | b_cnstr[-1]=c_cnstr[-1] 26 | for k in range(1,len(c_cnstr)-1): 27 | b_cnstr[k]=c_cnstr[k] 28 | b_cnstr[k-1]=b_cnstr[k] 29 | return b_cnstr, c_cnstr, K_cnstr 30 | 31 | 32 | 33 | 34 | 35 | def get_SS(params, bvec_guess, SS_graphs): 36 | start_time = time.clock() 37 | beta, sigma, nvec, L, A, alpha, delta, SS_tol, bq_distr, chi = params 38 | f_params = (nvec, A, alpha, delta, bq_distr, beta) 39 | b1_cnstr, c1_cnstr, K1_cnstr = feasible(f_params, bvec_guess) 40 | try: 41 | if b1_cnstr.max() or c1_cnstr.max() or K1_cnstr.max(): 42 | raise cstError 43 | 44 | else: 45 | # errors=zero_func(bvec_guess,beta, sigma, nvec, L, A, alpha, delta) 46 | b = opt.root(utils.EulerSys_ss, bvec_guess, args=(beta, sigma, nvec, A, alpha, delta, bq_distr,chi), tol=SS_tol) 47 | except cstError: 48 | print ('Did not pass the feasible test') 49 | if b.success: 50 | b_ss = b.x 51 | # iterations=b.nit 52 | 53 | K_ss, K_cnstr = utils.get_K(b_ss) 54 | L=utils.get_L(nvec) 55 | w_ss = utils.get_w(K_ss,L, (A, alpha)) 56 | r_ss = utils.get_r(K_ss, L, (A, alpha, delta)) 57 | Y_ss = utils.get_Y(K_ss, L, (A, alpha)) 58 | c_ss, c_cnstr = utils.get_cvec_ss(r_ss, w_ss, b_ss, nvec, bq_distr) 59 | EulErr_ss = utils.EulerSys_ss(b_ss, beta, sigma, nvec, A, alpha, delta, bq_distr, chi) 60 | C_ss=utils.get_C(c_ss) 61 | RCerr_ss = Y_ss - C_ss - delta * K_ss 62 | BQ_ss = b_ss[-1] 63 | 64 | ss_time = time.clock() - start_time 65 | ss_output={'b_ss': b_ss, 'c_ss': c_ss, 'w_ss': w_ss, 'r_ss': r_ss, 'K_ss': K_ss, 'Y_ss': Y_ss, 'C_ss': C_ss, 66 | 'EulErr_ss': EulErr_ss, 'RCerr_ss': RCerr_ss, 'BQ_ss': BQ_ss, 'ss_time': ss_time} 67 | 68 | # print('\n Savings: \t\t\t {} \n Capital and Labor: \t\t {} \n Wage and Interest rate: \t {} \n Consumption: \t\t\t {}'.format( 69 | # b_ss, np.array([K_ss, L]), np.array([w_ss, r_ss]), c_ss)) 70 | # 71 | # print('Euler errors: ', EulErr_ss) 72 | # print('Resource Constraint error: ', RCerr_ss) 73 | # print('Time needed: ', ss_time) 74 | # print ('It took {iterations} iterations to get the solution.') 75 | if SS_graphs: 76 | cur_path = os.path.split(os.path.abspath(__file__))[0] 77 | output_fldr = "images" 78 | output_dir = os.path.join(cur_path, output_fldr) 79 | if not os.access(output_dir, os.F_OK): 80 | os.makedirs(output_dir) 81 | 82 | age = np.arange(21, 101) 83 | fig, ax = plt.subplots() 84 | plt.plot(age, c_ss, marker='D', label='Consumption') 85 | plt.plot(age, b_ss, marker='D', label='Savings') 86 | minorLocator = MultipleLocator(1) 87 | ax.xaxis.set_minor_locator(minorLocator) 88 | plt.grid(b=True, which='major', color='0.65', linestyle='-') 89 | plt.title('Steady-state consumption and savings') 90 | plt.xlabel('Age') 91 | plt.ylabel('Consumption units') 92 | plt.legend() 93 | output_path = os.path.join(output_dir, 'ss_bc') 94 | plt.savefig(output_path) 95 | # plt.show() 96 | plt.close() 97 | 98 | return ss_output 99 | 100 | # def EulerSys(bvec, params): 101 | # 102 | # beta, sigma, nvec, L, A, alpha, delta = params 103 | # K, K_cnstr = get_K(bvec) 104 | # try: 105 | # if K_cnstr: 106 | # raise cstError 107 | # 108 | # 109 | # else: 110 | # r_params =np.array( [A, alpha, delta]) 111 | # r = get_r(r_params, K, L) 112 | # w_params = np.array([A, alpha]) 113 | # w = get_w(w_params, K, L) 114 | # cvec, c_cnstr = get_cvec(r, w, bvec, nvec) 115 | # b_err_params = np.array([beta, sigma]) 116 | # b_err_vec = get_b_errors(b_err_params, r, cvec, c_cnstr) 117 | # except cstError: 118 | # print ('Did not pass the feasible test') 119 | # 120 | # return b_err_vec 121 | 122 | # def get_b_errors(params, r, cvec, c_cnstr): 123 | # beta, sigma = params 124 | # # try: 125 | # # if c_cnstr.max(): 126 | # # raise cstError 127 | # # 128 | # # else: 129 | # MU_c12=get_MUc(cvec[:-1],sigma) 130 | # MU_c23=get_MUc(cvec[1:],sigma) 131 | # b_errors = (beta * (1 + r) * MU_c23) - MU_c12 132 | # # except cstError: 133 | # # print ('Did not pass the feasible test') 134 | # return b_errors 135 | 136 | 137 | # 138 | # def get_MUc(cvec,sigma): 139 | # epsilon = 1e-4 140 | # c_cnstr = cvec < epsilon 141 | # muc = cvec ** (-sigma) 142 | # m1 = (-sigma) * epsilon ** (-sigma - 1) 143 | # m2 = epsilon ** (-sigma) - m1 * epsilon 144 | # muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 145 | # 146 | # return muc 147 | 148 | # def MU_n_stitch(nvec, params): 149 | # l_tilde, b, upsilon = params 150 | # epsilon_lb = 1e-6 151 | # epsilon_ub = l_tilde - epsilon_lb 152 | # nl_cstr = nvec < epsilon_lb 153 | # nu_cstr = nvec > epsilon_ub 154 | # 155 | # mun = ((b / l_tilde) * ((nvec / l_tilde) ** (upsilon - 1)) * (1 - ((nvec / l_tilde) ** upsilon)) **\ 156 | # ((1 - upsilon) / upsilon)) 157 | # m1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_lb ** (upsilon - 2)) * \ 158 | # ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 159 | # (1 + ((epsilon_lb / l_tilde) ** upsilon) * ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** (-1)))) 160 | # m2 = ((b / l_tilde) * ((epsilon_lb / l_tilde) ** (upsilon - 1)) * \ 161 | # ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (m1 * epsilon_lb)) 162 | # q1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_ub ** (upsilon - 2)) * \ 163 | # ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 164 | # (1 + ((epsilon_ub / l_tilde) ** upsilon) * ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** (-1)))) 165 | # q2 = ((b / l_tilde) * ((epsilon_ub / l_tilde) ** (upsilon - 1)) * \ 166 | # ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (q1 * epsilon_ub)) 167 | # mun[nl_cstr] = m1 * nvec[nl_cstr] + m2 168 | # mun[nu_cstr] = q1 * nvec[nu_cstr] + q2 169 | # return mun 170 | 171 | class cstError (Exception): 172 | pass 173 | 174 | -------------------------------------------------------------------------------- /Students/Fiona/PS5/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.optimize as opt 3 | import matplotlib.pyplot as plt 4 | from matplotlib.ticker import MultipleLocator 5 | import os 6 | 7 | 8 | ''' 9 | Ellip filling for disutility of labor 10 | ''' 11 | def fit_ellip(elast_Frisch, l_tilde): 12 | b_i=0.1 13 | upsi_i=0.3 14 | l_sup=np.linspace(0.05,0.95, 1000) 15 | fargs=(elast_Frisch,l_tilde,l_sup) 16 | bnds=((1e-10, None), (1e-10, None)) 17 | params_init=np.array([b_i,upsi_i]) 18 | result=opt.minimize(MU_err,params_init,args=(fargs),bounds=bnds) 19 | b_ellip, upsilon=result.x 20 | sum_err=result.fun 21 | return b_ellip, upsilon 22 | 23 | 24 | def MU_err (params,*args): 25 | bi, ui = params 26 | theta, l_tilde, l_sup=args 27 | MU_cfe= l_sup**(1/theta) 28 | MU_elp=1/l_sup*bi*((l_sup/l_tilde)**ui)*(1-(l_sup/l_tilde)**ui)**(1/ui-1) 29 | sum_sqerr=((MU_cfe-MU_elp)**2).sum() 30 | return sum_sqerr 31 | 32 | ''' 33 | Stiching functions for U(c) and g(b) 34 | ''' 35 | def MU_c_stitch(cvec, sigma): 36 | epsilon = 1e-4 37 | c_cnstr = cvec < epsilon 38 | muc = cvec ** (-sigma) 39 | m1 = (-sigma) * epsilon ** (-sigma - 1) 40 | m2 = epsilon ** (-sigma) - m1 * epsilon 41 | muc[c_cnstr] = m1 * cvec[c_cnstr] + m2 42 | 43 | return muc 44 | 45 | def MU_n_stitch(nvec, params): 46 | l_tilde, b, upsilon = params 47 | epsilon_lb = 1e-6 48 | epsilon_ub = l_tilde - epsilon_lb 49 | nl_cstr = nvec < epsilon_lb 50 | nu_cstr = nvec > epsilon_ub 51 | 52 | mun = ((b / l_tilde) * ((nvec / l_tilde) ** (upsilon - 1)) * (1 - ((nvec / l_tilde) ** upsilon)) **\ 53 | ((1 - upsilon) / upsilon)) 54 | m1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_lb ** (upsilon - 2)) * \ 55 | ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 56 | (1 + ((epsilon_lb / l_tilde) ** upsilon) * ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** (-1)))) 57 | m2 = ((b / l_tilde) * ((epsilon_lb / l_tilde) ** (upsilon - 1)) * \ 58 | ((1 - ((epsilon_lb / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (m1 * epsilon_lb)) 59 | q1 = (b * (l_tilde ** (-upsilon)) * (upsilon - 1) * (epsilon_ub ** (upsilon - 2)) * \ 60 | ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) * \ 61 | (1 + ((epsilon_ub / l_tilde) ** upsilon) * ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** (-1)))) 62 | q2 = ((b / l_tilde) * ((epsilon_ub / l_tilde) ** (upsilon - 1)) * \ 63 | ((1 - ((epsilon_ub / l_tilde) ** upsilon)) ** ((1 - upsilon) / upsilon)) - (q1 * epsilon_ub)) 64 | mun[nl_cstr] = m1 * nvec[nl_cstr] + m2 65 | mun[nu_cstr] = q1 * nvec[nu_cstr] + q2 66 | return mun 67 | 68 | ''' 69 | Firm utilities: 70 | calculate wage and interest rate 71 | ''' 72 | 73 | def get_w(r, params): 74 | A, alpha, delta = params 75 | w = (1 - alpha) * A * (((alpha * A) / (r + delta)) ** (alpha / (1 - alpha))) 76 | return w 77 | 78 | def get_r(K, L, params): 79 | A, alpha, delta = params 80 | r = alpha * A * ((L / K) ** (1 - alpha)) - delta 81 | return r 82 | 83 | ''' 84 | Household utilities 85 | ''' 86 | #Calculate the remaning consumptions in one's lifetime. 87 | def get_c(c1, r, beta, sigma, p): 88 | cvec = np.zeros(p) 89 | cvec[0] = c1 90 | cs = c1 91 | for s in range (p - 1): 92 | cvec[s + 1] = cs * (beta * (1 + r[s + 1])) ** (1 / sigma) 93 | cs = cvec[s + 1] 94 | return cvec 95 | 96 | def get_b(cvec, nvec, r, w, p, bs = 0.0): # function for calculating lifetime savings, given consumption and labor decisions 97 | bvec = np.zeros(p) 98 | bvec[0] = bs 99 | for s in range (p-1): 100 | bvec[s + 1] = (1 + r[s]) * bs + w[s] * nvec[s] - cvec[s] 101 | bs = bvec[s + 1] 102 | s += 1 103 | return bvec 104 | 105 | def get_b_last(c1, *args): # function for last-period savings, given intial guess c1 106 | r, w, beta, sigma, l_ub, b, upsilon, p, bs, chi = args 107 | cvec = get_c(c1, r, beta, sigma, p) 108 | nvec = get_n(cvec, sigma, l_ub, b, upsilon, w, p, chi) 109 | bvec = get_b(cvec, nvec, r, w, p, bs) 110 | b_last = (1 + r[-1]) * bvec[-1] + w[-1] * nvec[-1] - cvec[-1] 111 | return b_last 112 | 113 | ######## Euler Equations 114 | 115 | def get_n_errors(nvec, *args): # function for calculating intratemporal euler error 116 | cvec, sigma, l_ub, b, upsilon, w, chi = args 117 | muc = MU_c_stitch(cvec, sigma) 118 | mun = MU_n_stitch(nvec, (l_ub, b, upsilon)) 119 | n_errors = w * muc - chi*mun 120 | return n_errors 121 | 122 | def get_n(cvec, sigma, l_ub, b, upsilon, w, p, chi): # function for labor supply, calculated from intratemporal euler, given path of lifetime consumption 123 | n_args = (cvec, sigma, l_ub, b, upsilon, w, chi) 124 | n_guess = 0.5 * l_ub * np.ones(p) 125 | result = opt.root(get_n_errors, n_guess, args = (n_args), method = 'lm') 126 | if result.success: 127 | nvec = result.x 128 | else: 129 | raise ValueError("failed to find an appropriate labor decision") 130 | return nvec 131 | 132 | def get_b_errors(cvec, r, *args): # function for calculating intertemporal euler error 133 | beta, sigma = args 134 | mu_c = MU_c_stitch(cvec[:-1], sigma) 135 | mu_c1 = MU_c_stitch(cvec[1:], sigma) 136 | 137 | b_errors = beta * (1 + r) * mu_c1 - mu_c 138 | 139 | return b_errors 140 | 141 | 142 | ######## Calculate aggregates 143 | 144 | def get_L(narr): # function for aggregate labor supply 145 | epsilon = 0.01 146 | a = epsilon / np.exp(1) 147 | b = 1 / epsilon 148 | if narr.ndim == 1: # This is the steady-state case 149 | L = narr.sum() 150 | L_cstr = L < epsilon 151 | if L_cstr: 152 | print('get_L() warning: Distribution of savings and/or ' + 153 | 'parameters created L < epsilon') 154 | # Force K >= eps by stitching a * exp(b * K) for K < eps 155 | L = a * np.exp(b * L) 156 | 157 | elif narr.ndim == 2: # This is the time path case 158 | L = narr.sum(axis=0) 159 | L_cstr = L < epsilon 160 | if L.min() < epsilon: 161 | print('get_L() warning: Aggregate capital constraint is ' + 162 | 'violated (L < epsilon) for some period in time ' + 163 | 'path.') 164 | L[L_cstr] = a * np.exp(b * L[L_cstr]) 165 | return L, L_cstr 166 | 167 | def get_K(barr): # function for aggregate capital supply 168 | epsilon = 0.01 169 | a = epsilon / np.exp(1) 170 | b = 1 / epsilon 171 | if barr.ndim == 1: # This is the steady-state case 172 | K = barr.sum() 173 | K_cstr = K < epsilon 174 | if K_cstr: 175 | print('get_K() warning: Distribution of savings and/or ' + 176 | 'parameters created K < epsilon') 177 | # Force K >= eps by stitching a * exp(b * K) for K < eps 178 | K = a * np.exp(b * K) 179 | 180 | elif barr.ndim == 2: # This is the time path case 181 | K = barr.sum(axis=0) 182 | K_cstr = K < epsilon 183 | if K.min() < epsilon: 184 | print('get_K() warning: Aggregate capital constraint is ' + 185 | 'violated (K < epsilon) for some period in time ' + 186 | 'path.') 187 | K[K_cstr] = a * np.exp(b * K[K_cstr]) 188 | 189 | return K, K_cstr 190 | 191 | def get_Y(K, L, params): # function for aggregate output 192 | A, alpha = params 193 | Y = A * (K ** alpha) * (L ** (1 - alpha)) 194 | return Y 195 | 196 | def get_C(carr): 197 | if carr.ndim == 1: 198 | C = carr.sum() 199 | elif carr.ndim == 2: 200 | C = carr.sum(axis=0) 201 | 202 | return C 203 | --------------------------------------------------------------------------------