Skip to content

Commit

Permalink
Move output to output folder
Browse files Browse the repository at this point in the history
  • Loading branch information
korenmiklos committed Sep 2, 2019
1 parent 7ed0aac commit 479a0e0
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 15 deletions.
Binary file removed Admissible-EOS.pdf
Binary file not shown.
Binary file removed CES0.5-model-data.pdf
Binary file not shown.
Binary file removed CES2-model-data.pdf
Binary file not shown.
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TABLES = $(CES) baseline china_1972 no_china no_io_linkages labor_adjustment tra
# default number of Julia threads to use. otherwise `make tables PROCS=12`
PROCS = 2

tables: $(foreach table,$(TABLES),experiments/$(table)/output_table.csv)
tables: $(foreach table,1 2 3 4left 4right 5left 5center 5right 6left 6right 7 8left 8right,output/table$(table).csv)
ces_tables: $(foreach table,$(CES),experiments/$(table)/output_table.csv) experiments/baseline/output_table.csv

# this takes too long to run, only run if explicitly asked `make S500`
Expand Down Expand Up @@ -48,3 +48,31 @@ template: scenario_template.jl
# install the Julia package dependencies
install: install.jl
julia install.jl

# copy tables to match the order in the paper
output/table1.csv: experiments/baseline/output_table.csv
cp $< $@
output/table2.csv: output/volatility_by_decade.csv
cp $< $@
output/table3.csv: experiments/trade_imbalance/output_table.csv
cp $< $@
output/table4left.csv: experiments/theta2/output_table.csv
cp $< $@
output/table4right.csv: experiments/theta8/output_table.csv
cp $< $@
output/table5left.csv: experiments/rho0005/output_table.csv
cp $< $@
output/table5center.csv: experiments/labor_adjustment/output_table.csv
cp $< $@
output/table5right.csv: experiments/rho002/output_table.csv
cp $< $@
output/table6left.csv: experiments/CES0.5/output_table.csv
cp $< $@
output/table6right.csv: experiments/CES1.5/output_table.csv
cp $< $@
output/table7.csv: experiments/no_io_linkages/output_table.csv
cp $< $@
output/table8left.csv: experiments/no_china/output_table.csv
cp $< $@
output/table8right.csv: experiments/china_1972/output_table.csv
cp $< $@
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Replication code for Caselli, Koren, Lisicky and Tenreyro. 2019. "Diversification Through Trade." The Quarterly Journal of Economics
# Replication Data for: 'Diversification Through Trade'
## Citation and license
Please cite as

Caselli, Francesco, Miklós Koren, Milan Lisicky, Silvana Tenreyro. 2019. "Replication Package for Diversification Through Trade." The Quarterly Journal of Economics.
Caselli, Francesco; Koren, Miklós; Lisicky, Milan; Tenreyro, Silvana, 2019, "Replication Data for: 'Diversification Through Trade'", The Quarterly Journal of Economics.

The software provided here (`.jl` and `.ipynb` files) is licensed under licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/). To use the data provided in the `data` folder, please check the license terms of the original data vendors.

## Data
Data are from the following sources.
- EU Klems Database (March 2008)
- UN National Accounts (2017)
- UN National Accounts (2012)
- UNIDO INDTSTAT2
- Penn World Table 7.1
- World Development Indicators (October 2015)
Expand All @@ -33,13 +33,13 @@ estimation. The details are described in the Appendix of Caselli, Koren, Lisicky
## Requirements
The code runs Julia 0.6 on Mac OS X and Linux. (We have not tested it on Windows.) The necessary Julia packages are installed by `install.jl` or `make install`.

The `Makefile` runs all the necessary computations in the correct order. If you want to reproduce the tables in our paper, simply run `make` or `make tables`.
## Workflow
The `Makefile` runs all the necessary computations in the correct order. If you want to reproduce the tables in our paper, run `make` or `make tables`.

Both Julia and Make can run in parallel. Computing the equilibrium for a given set of parameters takes about 1 minute on a single 3.8GHz CPU core. Each period's equilibrium can be computed in parallel (in Julia) and each scenario can be computed in parallel (in Make). With 44 scenarios (see below) and 36 time periods, total run time should be about 1600 minutes. The Makefile is set to run 10 Julia threads in parallel (`PROCS = -p10`). If you have fewer cores, set `PROCS` accordingly. You can then run Make jobs in parallel with `make -j4 tables`.

To run the code in an AWS EC2 instance, follow the steps in `notebooks/aws-recipe.md`. You need to launch an instance from an EC2 image with Julia 0.6 preinstalled.

## Workflow
The core logic is in two files.
- `equilibrium.jl` calculates the equilibrium prices and quantities given a set of parameters.
- `calibrate_params.jl` calibrates parameters to match a set of data moments.
Expand All @@ -52,8 +52,8 @@ The `actual` scenario does not change any of the calibrated parameters. The `kap

The results of each run are saved in `results.jld2` (a JLD2 Julia file format) in the _scenario_ folder, such as `experiments/CES2/kappa1972/results.jld2`. Most of our tables require comparisons of four scenarios (with and without trade cost changes, with and without sectoral shocks). These tables are saved in the _experiment_ folder, such as `experiments/CES2/output_table.csv`.

## Technical details
The calibration algorithm is described in Section [] in the paper. The equilibrium solution algorithm is described in Section []. The basic outline of the equilibrium solution can be described by four nested loops.
### Technical details
The calibration algorithm is described in Section III in the paper. The equilibrium solution algorithm is described in Section II.B. The basic outline of the equilibrium solution can be described by four nested loops.

### Algorithm
- The __outer loop__ solves for equilibrium labor shares, given expected wages. Expectations are taken over `S` possible realizations of future productivity shocks.
Expand All @@ -70,11 +70,32 @@ R_nt = sum(w_njt .* L_njt ./ beta_j, 3)
```
where the summation is across the third, j, dimension.

## Output
Tables and figured are saved in the `output` folder.

| File | Exhibit | Script |
---------------------------
output/Figure2.pdf | Figure 2 | notebooks/Create Figure 2.ipynb
output/table1.csv | Table 1 | experiments/baseline
output/table2.csv | Table 2 | notebooks/Volatility by decade.ipynb
output/table3.csv | Table 3 | experiments/trade_imbalance
output/table4left.csv | Table 4, left panel | experiments/theta2
output/table4right.csv | Table 4, right panel | experiments/theta8
output/table5left.csv | Table 5, left panel | experiments/rho0005
output/table5center.csv | Table 5, center panel | experiments/labor_adjustment
output/table5right.csv | Table 5, right panel | experiments/rho002
output/table6left.csv | Table 6, left panel | experiments/CES0.5
output/table6right.csv | Table 6, right panel | experiments/CES1.5
output/table7.csv | Table 7 | experiments/no_io_linkages
output/table8left.csv | Table 8, left panel | experiments/no_china
output/table8right.csv | Table 8, right panel | experiments/china_1972
output/trade_share.pdf | Supplementary figure | notebooks/Compare scenarios.ipynb

## References
- EU KLEMS Database, March 2008. Marcel Timmer, Mary O'Mahony & Bart van Ark, The EU KLEMS Growth and Productivity Accounts: An Overview, University of Groningen & University of Birmingham. http://www.euklems.net/euk08i.shtml
- Julia: A Fresh Approach to Numerical Computing. Jeff Bezanson, Alan Edelman, Stefan Karpinski and Viral B. Shah (2017) SIAM Review, 59: 65–98. doi: 10.1137/141000671. url: https://julialang.org/research/julia-fresh-approach-BEKS.pdf.
- Penn World Table 7.1, 2012. Alan Heston, Robert Summers and Bettina Aten, Penn World Table Version 7.1 Center for International Comparisons of Production, Income and Prices at the University of Pennsylvania, November 2012. https://www.rug.nl/ggdc/productivity/pwt/pwt-releases/pwt-7.1
- UN Comtrade, 2015. "United Nations Commodity Trade Statistics Database." United Nations Staistics Division. https://comtrade.un.org/
- UN National Accounts, 2017. "National Accounts Official Country Data. Table 2.1 Value added by industries at current prices (ISIC Rev. 3)." United Nations Statistics Division. http://data.un.org/Data.aspx?d=SNA&f=group_code%3a201
- UN National Accounts, 2012. "National Accounts Official Country Data. Table 2.1 Value added by industries at current prices (ISIC Rev. 3)." United Nations Statistics Division. http://data.un.org/Data.aspx?d=SNA&f=group_code%3a201
- UNIDO INDTSTAT 2, 2019. "UNIDO Industrial Statistics Database at the 2-digit level of ISIC (Revision 3)." United Nations Industrial Development Organization. https://www.unido.org/researchers/statistical-databases
- World Development Indicators, October 2015. "World Development Indicators." The World Bank. http://databank.worldbank.org/data/download/archive/WDI_excel_2015_10.zip
2 changes: 1 addition & 1 deletion notebooks/Admissible EOS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"source": [
"using Plots\n",
"plot(sigmas', correlations', label=\"\", xlabel=\"Elasticity of substitution\", ylabel=\"Correlation of volatilities in model and data (w/o China)\", size=(800,500))\n",
"savefig(\"../Admissible-EOS.pdf\")"
"savefig(\"../output/Admissible-EOS.pdf\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/Compare scenarios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"outputs": [],
"source": [
"compare_trade([\"baseline/actual\", \"baseline/kappa1972\"], [\"Baseline\", \"Constant trade cost\"], 0)\n",
"savefig(\"../trade_share.pdf\")"
"savefig(\"../output/trade_share.pdf\")"
]
},
{
Expand Down
7 changes: 3 additions & 4 deletions notebooks/Create Figure 2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@
}
],
"source": [
"plot_model_data(\"baseline/actual\", \"../Figure2.pdf\")\n",
"plot_model_data(\"CES0.5/actual\", \"../CES0.5-model-data.pdf\")\n",
"plot_model_data(\"baseline/actual\", \"../output/Figure2.pdf\")\n",
"plot_model_data(\"CES0.5/actual\", \"../output/CES0.5-model-data.pdf\")\n",
"model_volatility = volatility(\"baseline/actual\") "
]
},
Expand Down Expand Up @@ -599,8 +599,7 @@
},
"outputs": [],
"source": [
"plot_model_data(\"CES0.5/actual\", \"../CES0.5-model-data.pdf\")\n",
"plot_model_data(\"CES1.5/actual\", \"../CES2-model-data.pdf\")\n"
"plot_model_data(\"CES1.5/actual\", \"../output/CES2-model-data.pdf\")\n"
]
},
{
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions output/table1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
country_names,actual,kappa1972,nosectoral,nosectoral_kappa1972,trade_barriers,diversification,specialization
Australia,0.000901942775696,0.000922506144756,0.00104803084019,0.001053587848003,-2.22907664910862,-0.602381658357782,-1.62669499075084
Austria,0.000537635959177,0.000948228793949,0.00069440379141,0.001809665290992,-43.3010300248674,-117.61523238896,74.3142023640924
Belgium and Luxembourg,0.00102264424094,0.003014133747278,0.00112084730178,0.004335936362543,-66.0717032924249,-106.667100080327,40.5953967879019
Canada,0.000593783644813,0.002192824804059,0.00107087725824,0.003269826178742,-72.9215191421559,-100.279279787029,27.3577606448732
China,0.006239774317195,0.006155142413154,0.007010221722551,0.006981666879466,1.37497881217967,0.463918479351593,0.911060332828081
Colombia,0.001101059367104,0.001954030477196,0.002506447083638,0.003778584881929,-43.6518836346905,-65.1032731135367,21.4513894788461
Denmark,0.000442946465664,0.002009248413984,0.000480901143154,0.001287403676397,-77.954619121192,-40.1395132443504,-37.8151058768415
Finland,0.000618587046923,0.000996266875389,0.00100047597326,0.001663900612578,-37.9095037480033,-66.5910566442343,28.681552896231
France,0.00019580945372,0.000262782583831,0.000259324378637,0.000189734643259,-25.4861372980626,26.4818673913442,-51.9680046894068
Germany,0.00024314544262,0.00052116797696,0.000430856830696,0.000686005587733,-53.3460509147322,-48.9571056390617,-4.38894527567055
Greece,0.000299020437898,0.000382989029137,0.000441925663269,0.000407885744884,-21.9245421802567,8.88796174184878,-30.8125039221055
India,0.001020008558809,0.001217111577111,0.000864048013052,0.000938025527107,-16.1943261413636,-6.07812097479604,-10.1162051665676
Ireland,0.001047578172297,0.002554804588061,0.002053221214635,0.003817008664529,-58.9957612729845,-69.0380570841368,10.0422958111523
Italy,0.000190296896478,0.000263198563488,0.000184265663613,0.000126776988546,-27.6983529254683,21.8423209858716,-49.5406739113399
Japan,0.000295994717055,0.000305358821735,0.000223180851716,0.000198772137679,-3.06659052034836,7.99345304590116,-11.0600435662495
Mexico,0.001050249961057,0.002429502228077,0.005228868108349,0.007485124260942,-56.7709817706892,-92.8690711421662,36.098089371477
Netherlands,0.000336490537215,0.001241481223508,0.000661532666296,0.002315652865271,-72.8960429812513,-133.237633212126,60.3415902308745
Norway,0.000840733434693,0.001256393645754,0.002095221222143,0.003226162153494,-33.0835970451012,-90.0148560263942,56.931258981293
Portugal,0.001561708174025,0.001664499204642,0.001715451462262,0.002719745473594,-6.17549292483395,-60.3361064115459,54.1606134867119
ROW,0.001649807045623,0.001631323472273,0.00238995755382,0.002414015906191,1.13304158640999,-1.47477510005261,2.60781668646261
South Korea,0.000852855663416,0.000863846876239,0.000792890681852,0.000877294318542,-1.27235660919126,-9.77067105419964,8.49831444500838
Spain,0.000241604222762,0.001237539718996,0.000253294586926,0.000795073121127,-80.4770530551078,-43.778678444419,-36.6983746106888
Sweden,0.000346159381,0.000592327952993,0.000530996037515,0.000691129586373,-41.5595061400032,-27.0346094673786,-14.5248966726246
United Kingdom,0.000236407675674,0.000600182168414,0.000183170833737,0.000360931349789,-60.6106798709909,-29.6177603079941,-30.9929195629968
United States,0.000261762573356,0.000266192095183,0.000359518686928,0.000337773188841,-1.66403206812752,8.16909986442042,-9.83313193254795
File renamed without changes.
26 changes: 26 additions & 0 deletions output/table3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"country_names","actual","kappa1972","nosectoral","nosectoral_kappa1972","trade_barriers","diversification","specialization"
"Australia",0.0008542716612979551,0.0008869510967231913,0.0009968502666681148,0.001012341421178595,-3.684468686714431,-1.7465624167681544,-1.9379062699462644
"Austria",0.0005206432719978354,0.0009297723693467961,0.0006644639139452534,0.0017753359455092114,-44.00314645146865,-119.47784943796425,75.4747029864956
"Belgium and Luxembourg",0.0009936974730767728,0.002877934370547796,0.0011030588291980222,0.004359283308470804,-65.47185080917501,-113.14450088217197,47.67265007299696
"Canada",0.000575438525043696,0.0022216074707243874,0.0010767175425847601,0.0033140161660575227,-74.0981009189681,-100.70629726246189,26.60819634349379
"China",0.0062566496058658804,0.006149960711291366,0.007032293084166565,0.006934324877995209,1.7347898561145694,1.5929891388002737,0.14180071731429567
"Colombia",0.001047941620528721,0.0018847367993496185,0.002486931725443539,0.0037461009113969497,-44.39851649894337,-66.80875474962458,22.41023825068121
"Denmark",0.0004832317281309594,0.002012098877012407,0.00047545220141505376,0.0013190419744761577,-75.98369873112455,-41.92586073670882,-34.057837994415735
"Finland",0.000656807716947457,0.0010351952960536862,0.001047991156505518,0.0017218974026702522,-36.552289268382225,-65.09943087393866,28.547141605556444
"France",0.00020181156684027633,0.00026941170310292815,0.0002597429163224108,0.00019099336448688748,-25.09175937202154,25.518398437672058,-50.610157809693604
"Germany",0.00024648164275143985,0.0005224534488999139,0.0004510289607743581,0.0007095369898739473,-52.82227665059242,-49.47962916962416,-3.3426474809682607
"Greece",0.0003152151978208216,0.0004189222924226812,0.0004019341663874655,0.0003920077122279313,-24.755687743926966,2.3695215888675305,-27.125209332794483
"India",0.0010099219911639903,0.0011971921419061918,0.0008593840662970158,0.0009463932819317106,-15.642447372234374,-7.267773700565488,-8.374673671668885
"Ireland",0.0011511486026106828,0.0025686697789394017,0.0019939700461019745,0.0037295682722509015,-55.18502954139985,-67.56797780622279,12.382948264822936
"Italy",0.00019972881814539378,0.00027266280053349915,0.00018906458004641652,0.00013122201306685149,-26.748783569082704,21.213956163579613,-47.96273973266231
"Japan",0.000305082146389107,0.0003064314649680526,0.0002247837524446062,0.00020216323697475584,-0.4403329074206783,7.381916694556383,-7.82224960197706
"Mexico",0.001133331952235176,0.0025442181066413364,0.005342828952666665,0.007716386001523404,-55.454607084323214,-93.29220017186773,37.83759308754452
"Netherlands",0.0003360263397009718,0.0012766053315435282,0.0006779556182033284,0.0023541814271956065,-73.67813439297748,-131.30336898762388,57.6252345946464
"Norway",0.0008168483642839313,0.0012325522980426585,0.0020510326412901234,0.0031546571302833973,-33.72708277116366,-89.53976969138535,55.81268692022168
"Portugal",0.0015862304716957884,0.0017012349289203977,0.0017648988764110635,0.002798276047696702,-6.760057371828767,-60.74276713454379,53.98270976271502
"ROW",0.0016673626005009263,0.0016549505469815617,0.0023943039021342176,0.002416279016615745,0.7499954329150627,-1.3278411564386414,2.077836589353704
"South Korea",0.000896581054057798,0.0008991085101573594,0.0008450015650398345,0.0009150116777135972,-0.2811069043400656,-7.786614394463882,7.505507490123816
"Spain",0.00023462085842290776,0.0011778124053852526,0.0002520057605863782,0.0007665637174650665,-80.07994674277816,-43.68759868091054,-36.39234806186762
"Sweden",0.0003537464329879398,0.000600688261701615,0.0005346447620930088,0.0007020466561827368,-41.109814267744206,-27.86834782080076,-13.24146644694344
"United Kingdom",0.00024093689934133922,0.000592551169141418,0.00019434414158450052,0.00037149535462164244,-59.33905595183505,-29.89635701737399,-29.44269893446105
"United States",0.0002689944207993223,0.00027500067114923934,0.00036453431384501114,0.0003457759785172597,-2.184085705979067,6.821196199034551,-9.005281905013618
Loading

0 comments on commit 479a0e0

Please sign in to comment.