Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE (yet): Overhaul to make reproducible #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Code/Fortran/Combined Fortran data.xlsx
Binary file not shown.
70 changes: 70 additions & 0 deletions Code/Fortran/Compile data/01 Compile data.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

*******************************
** Privileged & Confidential **
*******************************
clear
capture log close
set more off
set type double

global scripts = c(pwd)
global scripts = subinstr("$scripts","\","/",.)
global path "$scripts/.."

***
forval year=1/80{

if `year' < 10 import delimited using "$path/year0`year'.txt", clear
if `year' >= 10 import delimited using "$path/year`year'.txt", clear

di "Importing `year'"
assert _N == 1203

* Match observations
gen obs = _n
replace obs = obs - (1203/3) if obs > (1203/3)
replace obs = obs - (1203/3) if obs > (1203/3)

* Seperate variables
gen var = ""
replace var = "RiskyShare" if _n <= (1203/3)
replace var = "Consumption" if _n > (1203/3) & _n <= (1203/3)*2
replace var = "Value" if mi(var)

* Reshape
reshape wide v1, i(obs) j(var) str
ds obs, not
foreach var in `r(varlist)'{
local newname = subinstr("`var'","v1","",.)
ren `var' `newname'
}

* Agent cash
ren obs Cash
replace Cash = Cash - 1

* Agents age
gen Age = `year' + 20

save "$scripts/`year'.dta", replace

}


* Combine
clear
forval year=1/80{
append using "$scripts/`year'.dta"
}

* Clean up
forval year=1/80{
erase "$scripts/`year'.dta"
}

* Output
order Age Cash RiskyShare Consumption Value
export excel using "$path/Combined Fortran data.xlsx", sheet("r.Data") firstrow(variables) sheetreplace


* EOF
Loading