Zhentao Shi and Huanhuan Zheng, "Structural Estimation of Behavioral Heterogeneity", Journal of Applied Econometrics, Vol. 33, No. 5, 2018, pp. 690-707. We provide code of XMM and ELXM that replicates the empirical results. All files are zipped in the file sz-files.zip. They are all ASCII files in DOS format. Unix/Linux users should use "unzip -a". ## Hosts * A static copy is hosted at Journal of Applied Econometrics [Data Archive](http://qed.econ.queensu.ca/jae/). * A dynamic copy is hosted at [Github](https://github.com/zhentaoshi/behavioral_heterogeneity) with Version 1.0 exactly the same as the copy in JAE Data Archive. The authors will maintain it for future update. ## Data * `raw_data.csv`: the raw dataset, downloaded from [Robert Shiller's webpage](http://www.econ.yale.edu/~shiller/data.htm). This paper only uses three columns of the dataset. * `date`: in the format `year.month` * `p`: S&P 500 index * `D`: Dividend ## Code * `master1_data_cleaning.R`: generate the detrended time series for each period. After running this script, three Rdata files will be saved in the folder. * `master2_estimation.R`: estimation by XMM and ELXM using the Rdata files generated by `master1_data_cleaning.R`. The following R scripts contain the user-defined functions used in `master2_estimation.R`. * `CUE.R`: XMM * `EL.R`: EXLM * `func5.R`: a collection of useful functions for the estimation procedures. ### Environment * No extra software is needed to run `master1_data_cleaning.R`. * The numerical optimization in `master2_estimation.R` depends on [`NLOPT`](https://nlopt.readthedocs.io/en/latest/) and [`MOSEK`](https://www.mosek.com/) via the R packages `nloptr` and `RMOSEK`. The software must be installed to run the code. ## Implementation 1. `R --vanilla data.out &` 2. `R --vanilla est.out &`