****************************************************************************************************************
***************************************************************************************************************
**
** "Catholic Censorship and the Demise of Knowledge Production in Early Modern Italy" (Blasutto and de la Croix)
**
**  How to replicate the model results and sensititity analysis
**
**  Software used by the authors: R-4.2.2 and RStudio 2022.12.0
**
***************************************************************************************************************
***************************************************************************************************************

******************
**Files Location
******************

The files related to the simulation and estimation of the model can be found in the following folder:

"\siminput"

*************************
**Files and Replication
************************

Most of the replications can be performed running the file "calibration_macro_shock.R" To make sure it works, first change line to your root directory on line 32. 
Below we explain how to use file "calibration_macro_shock.R"

1) Baseline Model

   Running the file as it is, the script estimate the baseline model and stores in "\simoutput" the following files used to build the simulation-based figures and tables in the paper: 
   (b.tex, qnc.tex, qr.tex, q.tex: Figure 4), (sq_uk.tex: Figure 5), (bc.tex, sq.tex,: Figure 6) (rel_qual.tex: Table 5), (normal.tex: first line in Table F.7). (sqCd.tex,bmc.tex: used only in slides)

   Other simulation results are stored in the file "output.txt" in "\simoutput". It contains the following information:
   -the overall effect of censorship on knowledge production (first reported in the abstract)
   -the share of revolutionary authors with and without censorship reported in page 24 under "The Role of Censorship in Knowledge Formation"
   -the numbers relative to Equation (13) are reported in lines (1149-1152)
   -the effect of keeping constant macro shocks on knowledge production (first reported in the abstract)
   -the bounds of parameter phi reported in appendix F.2

2) Standard Errors

   To generate Table 4 with standard errors, set serrors<-TRUE in line 38. It generates tempp.tex, which is stored in "\simoutput"

3) Sensitivity Analysis

   Sensitivity analysis can be done setting to "TRUE" one string at time in lines 41-50. Each sensitivity analysis associated with string "x" being true creates a x.tex file stored in "\simoutput".
                       x.tex file creates a line in Table F.7 in the appendix. Moreover, "output_ten_periods.txt", stored in the same folder, report parameter phi.

   *EXCEPTIONS* Sensitivity analysis "Time varying censorshiph rate" and "Self censorship" can be run using files "calibration_beta_variable.R" and "calibration_self_censorship.R",
                                       which can be found in "\siminput". These files also generates .tex files that creates a line in Table F.7 and also create "output_beta_variables.txt"
                                       and "output_self_censorshihp.txt" (both stored in \siminput) which contain variables and parameter values used in the text of appendix F.3.
 
4) Shocks

   The baseline model uses GDP to build macroeconomic shocks. On line 53-55 you can choose to use longevity or population shocks.

    To obtain the effect of keeping life expectancy constant on knowledge in periods 4 and 5 (mentioned at the end of page 27-beginning of page 28), set longe<-True on line 54 and then check
                                                                                          the last two lines of the file "output.txt" in "\simoutput"

    To obtain the effect of keeping the "combined" macro shocks (product of the last two rows of Table 7) constant on knowledge in periods 4 and 5 (mentioned at the end of page 27-beginning of page 28), set gdp_longe<-True on line 55 and then check
                                                                                          the last two lines of the file "output.txt" in "\simoutput"



