------------------------------------------------------------------------------------------------------------------------ name: master log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/maste > r.log log type: text opened on: 13 Sep 2026, 22:46:54 . . do "`here'/helpers/lp_helpers.do" . *! lp_helpers.do Helper programs for the Practicum 01 lab project . * . * Local Projections: From First Principles to Empirical Research, Practicum 01. . * Every do-file in the project loads this file before it does anything else, . * and tests/checks.do exercises each program before the replication runs. . * . * lp_root stop unless Stata is in the project's top folder . * lp_assert "label" : exp [if exp] assert exp, then count and record the result . * lp_close a b, tol(#) label(text) assert |a - b| < tol and print both numbers . * lp_sha256 "file" SHA-256 of a file in r(sha256), by shelling out (D35) . * lp_json_get using file, key(a.b.c) one entry of the Explorer's handoff record . * . * Globals the programs read, all optional: . * LP_RECORD CSV file that receives one line per check (master.do sets it) . * LP_STEP name of the step that is writing checks . * LP_SELFTEST 1 while tests/checks.do exercises the failure path . . version 19 . . *-------------------------------------------------------------------------- . capture program drop lp_root . program define lp_root 1. version 19 2. capture confirm file "master.do" 3. local rc1 = _rc 4. capture confirm file "helpers/lp_helpers.do" 5. if `rc1' | _rc { 6. display as error "Run this file from the lab project's top folder, the one that holds master.do." 7. display as error "Current folder: `c(pwd)'" 8. exit 601 9. } 10. end . . *-------------------------------------------------------------------------- . capture program drop lp_record . program define lp_record 1. version 19 2. args label result 3. if `"$LP_RECORD"' == "" exit 4. if "$LP_SELFTEST" == "1" exit 5. capture confirm file `"$LP_RECORD"' 6. local new = (_rc != 0) 7. local clean = subinstr(`"`label'"', char(34), "'", .) 8. tempname fh 9. file open `fh' using `"$LP_RECORD"', write append text 10. if `new' file write `fh' "step,check,result" _n 11. file write `fh' `"$LP_STEP,"`clean'",`result'"' _n 12. file close `fh' 13. end . . *-------------------------------------------------------------------------- . capture program drop lp_assert . program define lp_assert 1. version 19 2. * lp_assert "label" : expression [if exp] . gettoken label 0 : 0, parse(":") 3. gettoken colon 0 : 0, parse(":") 4. if `"`colon'"' != ":" { 5. display as error `"lp_assert: write lp_assert "label" : expression"' 6. exit 198 7. } 8. if "$LP_NPASS" == "" global LP_NPASS 0 9. if "$LP_NFAIL" == "" global LP_NFAIL 0 10. capture noisily assert `0' 11. local rc = _rc 12. if `rc' { 13. if "$LP_SELFTEST" != "1" global LP_NFAIL = $LP_NFAIL + 1 14. display as error `"FAIL `label'"' 15. lp_record `"`label'"' "fail" 16. exit `rc' 17. } 18. if "$LP_SELFTEST" != "1" global LP_NPASS = $LP_NPASS + 1 19. display as text `"pass `label'"' 20. lp_record `"`label'"' "pass" 21. end . . *-------------------------------------------------------------------------- . capture program drop lp_close . program define lp_close 1. version 19 2. * lp_close a b, tol(#) label(text) . * a and b are numbers or expressions; wrap an expression with spaces in ( ). . syntax anything(name=pair equalok), Tol(real) Label(string) 3. gettoken a rest : pair, match(paren1) 4. gettoken b rest : rest, match(paren2) 5. if `"`b'"' == "" | `"`rest'"' != "" { 6. display as error "lp_close: give exactly two numbers or parenthesized expressions" 7. exit 198 8. } 9. tempname va vb 10. scalar `va' = (`a') 11. scalar `vb' = (`b') 12. local d = abs(`va' - `vb') 13. display as text `"`label'"' _n /// > as text " value " as result %15.8f `va' /// > as text " target " as result %15.8f `vb' /// > as text " |diff| " as result %9.2e `d' as text " tol " %7.1e `tol' 14. lp_assert `"`label'"' : `d' < `tol' 15. end . . *-------------------------------------------------------------------------- . capture program drop lp_sha256 . program define lp_sha256, rclass 1. version 19 2. args filename 3. confirm file `"`filename'"' 4. tempfile out 5. if c(os) == "Windows" { 6. shell certutil -hashfile "`filename'" SHA256 > "`out'" 7. } 8. else { 9. shell (shasum -a 256 "`filename'" || sha256sum "`filename'") > "`out'" 2>/dev/null 10. } 11. local hash "" 12. capture confirm file "`out'" 13. if _rc == 0 { 14. tempname fh 15. file open `fh' using "`out'", read text 16. file read `fh' line 17. while r(eof) == 0 { 18. local cand = lower(subinstr(strtrim(`"`macval(line)'"'), " ", "", .)) 19. if ustrregexm(`"`cand'"', "^([0-9a-f]{64})") { 20. local hash = ustrregexs(1) 21. continue, break 22. } 23. file read `fh' line 24. } 25. file close `fh' 26. } 27. return local sha256 "`hash'" 28. end . . *-------------------------------------------------------------------------- . capture program drop lp_json_get . program define lp_json_get, rclass 1. version 19 2. * lp_json_get using file, key(lab2.settings.h) [display] . * Reads the record the Shock-to-Response Explorer writes with . * JSON.stringify(record, null, 2): one key or array element per line and . * two spaces of indentation per level. Returns . * r(found) 1 if the key exists . * r(n) number of values (elements, for an array) . * r(value) the value; array elements separated by spaces; strings . * unquoted, with characters that Stata macros cannot hold . * replaced . * r(direction) for a string: raise, lower, unchanged, or empty . * r(number) for a string: the first decimal number it contains . syntax using/, Key(string) [Display] 3. confirm file `"`using'"' 4. local value "" 5. local found 0 6. local n 0 7. local direction "" 8. local number "" 9. mata: _lp_json_get(`"`using'"', `"`key'"', "`display'" != "") 10. return local number `"`number'"' 11. return local direction `"`direction'"' 12. return local value `"`value'"' 13. return scalar n = `n' 14. return scalar found = `found' 15. end . . capture mata: mata drop _lp_json_get() . capture mata: mata drop _lp_json_scalar() . capture mata: mata drop _lp_macro_safe() . mata: ------------------------------------------------- mata (type end to exit) ---------------------------------------------- : string scalar _lp_json_scalar(string scalar s) > { > string scalar q, bs, out > q = char(34) > bs = char(92) > out = s > if (strlen(out) >= 2 & substr(out, 1, 1) == q & substr(out, strlen(out), 1) == q) { > out = substr(out, 2, strlen(out) - 2) > out = subinstr(out, bs + q, q, .) > out = subinstr(out, bs + "n", " ", .) > out = subinstr(out, bs + "t", " ", .) > out = subinstr(out, bs + bs, bs, .) > } > return(out) > } : : string scalar _lp_macro_safe(string scalar s) > { > string scalar out > out = subinstr(s, char(96), char(39), .) > out = subinstr(out, char(36), "S", .) > out = subinstr(out, char(34), char(39), .) > out = subinstr(out, char(92), "/", .) > out = subinstr(out, char(39), uchar(8217), .) > return(out) > } : : void _lp_json_get(string scalar fn, string scalar key, real scalar show) > { > string colvector lines > string rowvector stack > string scalar line, content, k, rest, path, values, elem, q, re, raw, low, dir > real scalar i, j, indent, level, collecting, clevel, found, n, hits > > q = char(34) > re = "^" + q + "([^" + q + "]+)" + q + ":[ ]*(.*)" > lines = cat(fn) > stack = J(1, 50, "") > collecting = 0 > clevel = 0 > found = 0 > n = 0 > values = "" > raw = "" > for (i = 1; i <= rows(lines); i++) { > line = lines[i] > content = strtrim(line) > if (content == "") continue > indent = strlen(line) - strlen(strltrim(line)) > level = indent / 2 > if (collecting) { > if (level == clevel & (content == "]" | content == "],")) { > found = 1 > break > } > if (substr(content, strlen(content), 1) == ",") content = substr(content, 1, strlen(content) - 1) > if (content == "[" | content == "]") continue > elem = _lp_json_scalar(content) > values = values + (n > 0 ? " " : "") + elem > n = n + 1 > continue > } > if (level < 1 | level > 50) continue > if (!ustrregexm(content, re)) continue > k = ustrregexs(1) > rest = ustrregexs(2) > stack[level] = k > for (j = level + 1; j <= 50; j++) stack[j] = "" > path = invtokens(stack[1..level], ".") > if (path != key) continue > if (substr(rest, strlen(rest), 1) == ",") rest = substr(rest, 1, strlen(rest) - 1) > if (rest == "[") { > collecting = 1 > clevel = level > continue > } > if (rest == "[]") { > found = 1 > break > } > if (rest == "{") { > found = 1 > values = "{object}" > n = 1 > break > } > raw = _lp_json_scalar(rest) > values = raw > n = 1 > found = 1 > break > } > if (show & found) printf("%s\n", (raw != "" ? raw : values)) > st_local("value", _lp_macro_safe(values)) > st_local("found", strofreal(found)) > st_local("n", strofreal(n)) > if (raw != "") { > low = ustrlower(raw) > dir = "" > hits = 0 > if (ustrregexm(low, "\b(raise|raises|raised|rise|rises|higher|increase|increases|up)\b")) { > dir = "raise" > hits = hits + 1 > } > if (ustrregexm(low, "\b(lower|lowers|lowered|reduce|reduces|fall|falls|decrease|decreases|down|smaller)\b")) { > dir = "lower" > hits = hits + 1 > } > if (ustrregexm(low, "\b(unchanged|no change|leave it)\b")) { > dir = "unchanged" > hits = hits + 1 > } > if (hits != 1) dir = "" > st_local("direction", dir) > if (ustrregexm(raw, "(-?[0-9]*[.][0-9]+)")) st_local("number", ustrregexs(1)) > } > } : end ------------------------------------------------------------------------------------------------------------------------ . end of do-file . global LP_NPASS 0 . global LP_NFAIL 0 . global LP_SELFTEST 0 . global LP_RECORD "output/assertions.csv" . capture erase "$LP_RECORD" . if "$R" == "" global R = cond("`mode'" == "solution", 500, 200) . if "$AUTHOR_CHECK" == "" global AUTHOR_CHECK 1 . local problem_set = cond("`mode'" == "solution", "solution/pset_solution.do", "starter/pset.do") . . display as text _n "Practicum 01 lab project" Practicum 01 lab project . display as text " problem set `problem_set'" problem set solution/pset_solution.do . display as text " draws R = $R; authors' script cross-check AUTHOR_CHECK = $AUTHOR_CHECK" draws R = 500; authors' script cross-check AUTHOR_CHECK = 1 . display as text " Stata `c(stata_version)', edition `c(edition_real)', `c(os)'" Stata 19.5, edition SE, Unix . display as text " started `c(current_date)' `c(current_time)'" started 13 Sep 2026 22:46:54 . . timer clear 1 . timer on 1 . . *-------------------------------------------------------------------------- . * 1. Checks on the data files and the helper programs . *-------------------------------------------------------------------------- . do "tests/checks.do" . *! checks.do Network-free checks on the data files and the helper programs . * . * Local Projections: From First Principles to Empirical Research, Practicum 01. . * . * master.do runs this file first. It needs no internet connection: the . * Ramey-Zubairy workbook is checked only when data/raw already holds a copy, . * and Task 5 of the problem set fetches it with data/raw/get_rz.do. . * The SHA-256 values below are the ones recorded in data/PROVENANCE.md. . * . * Writes output/checks.log. . * Run from the lab project's top folder: do tests/checks.do . . version 19 . clear . set more off . capture program list lp_assert . if _rc do helpers/lp_helpers.do . lp_root . capture mkdir output . capture log close checks . log using "output/checks.log", text replace name(checks) (file /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/checks.log not found) ------------------------------------------------------------------------------------------------------------------------ name: checks log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/check > s.log log type: text opened on: 13 Sep 2026, 22:46:54 . global LP_STEP checks . local npass0 = cond("$LP_NPASS" == "", 0, $LP_NPASS) . . *========================================================================== . * 1. The helper programs . *========================================================================== . lp_assert "helpers: lp_assert passes a true statement" : 2 + 2 == 4 pass helpers: lp_assert passes a true statement (file output/assertions.csv not found) . . global LP_SELFTEST 1 . capture lp_assert "helpers: a deliberately false statement" : 2 + 2 == 5 . local rc_assert = _rc . capture lp_close 1 1.1, tol(1e-6) label(helpers: two numbers that differ) . local rc_close = _rc . global LP_SELFTEST 0 . lp_assert "helpers: lp_assert stops with r(9) on a false statement" : `rc_assert' == 9 pass helpers: lp_assert stops with r(9) on a false statement . lp_assert "helpers: lp_close stops with r(9) when two numbers differ by more than tol" : `rc_close' == 9 pass helpers: lp_close stops with r(9) when two numbers differ by more than tol . lp_close 0.617322 (0.61732178 + 2e-7), tol(1e-6) label(helpers: lp_close accepts a difference below tol) helpers: lp_close accepts a difference below tol value 0.61732200 target 0.61732198 |diff| 2.00e-08 tol 1.0e-06 pass helpers: lp_close accepts a difference below tol . . * lp_sha256 on a text whose SHA-256 is known . tempfile known . tempname fh . file open `fh' using "`known'", write binary replace (file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000001 not found) . file write `fh' %17s "local projections" %1bu (10) . file close `fh' . lp_sha256 "`known'" . local sha "`r(sha256)'" . lp_assert "helpers: lp_sha256 returns the SHA-256 of a known text" : /// > "`sha'" == "d38550f8bb1ce55e64840a41105667865068f82bcada6c073fee3184649717e0" pass helpers: lp_sha256 returns the SHA-256 of a known text . . * lp_json_get on a small record laid out as the Explorer writes it . tempfile json . file open `fh' using "`json'", write text replace (file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000002 not found) . file write `fh' "{" _n . file write `fh' `" "lecture": "01","' _n . file write `fh' `" "lab2": {"' _n . file write `fh' `" "settings": {"' _n . file write `fh' `" "h": 1,"' _n . file write `fh' `" "control_y_lag": true"' _n . file write `fh' `" },"' _n . file write `fh' `" "beta_h": -1.050405,"' _n . file write `fh' `" "intervention_rows": ["' _n . file write `fh' `" 5,"' _n . file write `fh' `" 10"' _n . file write `fh' `" ]"' _n . file write `fh' `" },"' _n . file write `fh' `" "lab4": {"' _n . file write `fh' `" "hypothesis": "It will raise the estimate to about 0.43.","' _n . file write `fh' `" "used_in": 9"' _n . file write `fh' `" }"' _n . file write `fh' "}" _n . file close `fh' . . lp_json_get using "`json'", key(lecture) . local v "`r(value)'" . local f = r(found) . lp_assert "helpers: lp_json_get reads a top-level string" : "`v'" == "01" & `f' == 1 pass helpers: lp_json_get reads a top-level string . lp_json_get using "`json'", key(lab2.settings.h) . local v "`r(value)'" . lp_assert "helpers: lp_json_get reads a nested number" : `v' == 1 pass helpers: lp_json_get reads a nested number . lp_json_get using "`json'", key(lab2.settings.control_y_lag) . local v "`r(value)'" . lp_assert "helpers: lp_json_get reads a boolean" : "`v'" == "true" pass helpers: lp_json_get reads a boolean . lp_json_get using "`json'", key(lab2.beta_h) . local v "`r(value)'" . lp_assert "helpers: lp_json_get reads a negative number exactly" : abs(`v' - (-1.050405)) < 1e-12 pass helpers: lp_json_get reads a negative number exactly . lp_json_get using "`json'", key(lab2.intervention_rows) . local v "`r(value)'" . local n = r(n) . lp_assert "helpers: lp_json_get reads an array" : "`v'" == "5 10" & `n' == 2 pass helpers: lp_json_get reads an array . lp_json_get using "`json'", key(lab4.hypothesis) . local d "`r(direction)'" . local x "`r(number)'" . lp_assert "helpers: lp_json_get finds the direction and the number in a hypothesis" : "`d'" == "raise" & "`x'" == "0.4 > 3" pass helpers: lp_json_get finds the direction and the number in a hypothesis . lp_json_get using "`json'", key(lab9.missing) . local f = r(found) . lp_assert "helpers: lp_json_get reports a missing key" : `f' == 0 pass helpers: lp_json_get reports a missing key . . *========================================================================== . * 2. The simulated inputs in data/raw . *========================================================================== . local sha_hand_table "d58b48a56e73d38c682ee621250d25c64ce542bc11c73c73da281edb8a98041f" . local sha_onedraw_rho05_seed2 "5c85f2054698ca65681045ec0e8092460ae44e10867e30a23dc6f242b47232cd" . local sha_onedraw_rho09_seed2 "202051448cb02e7ab55f5cf0af399a76d29969b4de6cdb0a2d0699e725aa34cb" . . lp_sha256 "data/raw/hand_table.csv" . local s "`r(sha256)'" . lp_assert "data: hand_table.csv has the SHA-256 in PROVENANCE.md" : "`s'" == "`sha_hand_table'" pass data: hand_table.csv has the SHA-256 in PROVENANCE.md . import delimited using "data/raw/hand_table.csv", clear (encoding automatically selected: ISO-8859-2) (4 vars, 12 obs) . capture confirm numeric variable t s v y . local rc = _rc . lp_assert "data: hand_table.csv has 12 rows and the variables t, s, v, y" : `rc' == 0 & c(k) == 4 & _N == 12 pass data: hand_table.csv has 12 rows and the variables t, s, v, y . lp_assert "data: hand_table.csv dates run t = 1, ..., 12" : t == _n pass data: hand_table.csv dates run t = 1, ..., 12 . lp_assert "data: interventions exactly at t = 1, 5, 10, 12" : s == inlist(t, 1, 5, 10, 12) pass data: interventions exactly at t = 1, 5, 10, 12 . lp_assert "data: v is rounded to one decimal" : abs(v - round(v, 0.1)) < 1e-6 pass data: v is rounded to one decimal . generate double yrule = cond(t == 1, s + v, 0.5*y[_n-1] + s + v) . lp_assert "data: y follows y_t = 0.5 y_(t-1) + s_t + v_t with y_0 = 0 (1e-6)" : abs(y - yrule) < 1e-6 pass data: y follows y_t = 0.5 y_(t-1) + s_t + v_t with y_0 = 0 (1e-6) . . foreach tag in 05 09 { 2. local rho "0.`=substr("`tag'", 2, 1)'" 3. lp_sha256 "data/raw/onedraw_rho`tag'_seed2.csv" 4. local s "`r(sha256)'" 5. lp_assert "data: onedraw_rho`tag'_seed2.csv has the SHA-256 in PROVENANCE.md" : "`s'" == "`sha_onedraw_rho`tag' > _seed2'" 6. import delimited using "data/raw/onedraw_rho`tag'_seed2.csv", clear 7. capture confirm numeric variable t s v y 8. local rc = _rc 9. lp_assert "data: onedraw_rho`tag'_seed2.csv has 200 rows and the variables t, s, v, y" : `rc' == 0 & c(k) == 4 > & _N == 200 10. lp_assert "data: onedraw_rho`tag'_seed2.csv dates run t = 1, ..., 200" : t == _n 11. generate double yrule = `rho'*y[_n-1] + s + v 12. lp_assert "data: y follows y_t = `rho' y_(t-1) + s_t + v_t (1e-5, float storage)" : abs(y - yrule) < 1e-5 if _n > > 1 13. quietly summarize s 14. local ms = r(mean) 15. local ss = r(sd) 16. lp_assert "data: s in onedraw_rho`tag' has mean near 0 and standard deviation near 1" : abs(`ms') < 0.25 & `ss' > > 0.8 & `ss' < 1.2 17. } pass data: onedraw_rho05_seed2.csv has the SHA-256 in PROVENANCE.md (encoding automatically selected: ISO-8859-2) (4 vars, 200 obs) pass data: onedraw_rho05_seed2.csv has 200 rows and the variables t, s, v, y pass data: onedraw_rho05_seed2.csv dates run t = 1, ..., 200 (1 missing value generated) pass data: y follows y_t = 0.5 y_(t-1) + s_t + v_t (1e-5, float storage) pass data: s in onedraw_rho05 has mean near 0 and standard deviation near 1 pass data: onedraw_rho09_seed2.csv has the SHA-256 in PROVENANCE.md (encoding automatically selected: ISO-8859-2) (4 vars, 200 obs) pass data: onedraw_rho09_seed2.csv has 200 rows and the variables t, s, v, y pass data: onedraw_rho09_seed2.csv dates run t = 1, ..., 200 (1 missing value generated) pass data: y follows y_t = 0.9 y_(t-1) + s_t + v_t (1e-5, float storage) pass data: s in onedraw_rho09 has mean near 0 and standard deviation near 1 . . * The generator reproduces all three files byte for byte. . local simdir "`c(tmpdir)'/p01_simcheck" . capture mkdir "`simdir'" . quietly do "data/raw/make_sim_data.do" "`simdir'" . foreach f in hand_table onedraw_rho05_seed2 onedraw_rho09_seed2 { 2. lp_sha256 "`simdir'/`f'.csv" 3. local s "`r(sha256)'" 4. lp_assert "data: make_sim_data.do regenerates `f'.csv byte for byte" : "`s'" == "`sha_`f''" 5. } pass data: make_sim_data.do regenerates hand_table.csv byte for byte pass data: make_sim_data.do regenerates onedraw_rho05_seed2.csv byte for byte pass data: make_sim_data.do regenerates onedraw_rho09_seed2.csv byte for byte . . *========================================================================== . * 3. The authors' files in vendor/jel-code (CC0) . *========================================================================== . local sha_ssbias "07116508f0d0c633a6a0942e04867290a0fe808f254ea8b7bf3e0c4682a1e7e2" . local sha_allsim "730dae2639931ccab9b24cdbc198db8dadf731da6c540bf80065780d0303a6df" . local sha_means "720462bff571cccca5e504bda2eb7b230cfacc82abfc23c923088c8366f102a4" . local sha_cc0 "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499" . foreach pair in "SSBias_IntcpYLagdiffN_95.do ssbias" "all-simulate.do allsim" "SSBias_IntcpYLagdiffN_95.dta means" "LI > CENSE cc0" { 2. gettoken f key : pair 3. local key = strtrim("`key'") 4. lp_sha256 "vendor/jel-code/`f'" 5. local s "`r(sha256)'" 6. lp_assert "vendor: `f' is the file of JEL-Code commit 655696c (SHA-256)" : "`s'" == "`sha_`key''" 7. } pass vendor: SSBias_IntcpYLagdiffN_95.do is the file of JEL-Code commit 655696c (SHA-256) pass vendor: all-simulate.do is the file of JEL-Code commit 655696c (SHA-256) pass vendor: SSBias_IntcpYLagdiffN_95.dta is the file of JEL-Code commit 655696c (SHA-256) pass vendor: LICENSE is the file of JEL-Code commit 655696c (SHA-256) . use "vendor/jel-code/SSBias_IntcpYLagdiffN_95.dta", clear . capture confirm numeric variable t rl rt . local rc = _rc . lp_assert "vendor: the authors' shipped means hold 11 horizons with t, rl, rt" : `rc' == 0 & _N == 11 pass vendor: the authors' shipped means hold 11 horizons with t, rl, rt . lp_assert "vendor: horizons 0 to 10 and true response 0.95^h (1e-6)" : t == _n - 1 & abs(rt - 0.95^t) < 1e-6 pass vendor: horizons 0 to 10 and true response 0.95^h (1e-6) . . *========================================================================== . * 4. The benchmark files in replication/benchmark . *========================================================================== . lp_sha256 "replication/benchmark/REP01-levels-lp.csv" . local s "`r(sha256)'" . lp_assert "benchmark: REP01-levels-lp.csv has the SHA-256 in PROVENANCE.md" : /// > "`s'" == "1899da92df8a682ec9e13a45c7d9bebf307d2ccce78e71f31d4e9eb135ccdb30" pass benchmark: REP01-levels-lp.csv has the SHA-256 in PROVENANCE.md . import delimited using "replication/benchmark/REP01-levels-lp.csv", clear varnames(1) encoding(utf8) (21 vars, 11 obs) . lp_assert "benchmark: REP01-levels-lp.csv holds 11 REP01 rows" : _N == 11 & replication == "REP01" pass benchmark: REP01-levels-lp.csv holds 11 REP01 rows . lp_assert "benchmark: horizons 0 to 10 with n = 99 - h" : horizon == _n - 1 & n == 99 - horizon pass benchmark: horizons 0 to 10 with n = 99 - h . lp_assert "benchmark: every horizon has a mean" : coefficient < . pass benchmark: every horizon has a mean . . lp_sha256 "replication/benchmark/REP01-author-R200-v195.csv" . local s "`r(sha256)'" . lp_assert "benchmark: REP01-author-R200-v195.csv has the SHA-256 in PROVENANCE.md" : /// > "`s'" == "72cea43bb335f4c572c1ab3fcc97d8ec1a740278ae059593f447edf5341346c5" pass benchmark: REP01-author-R200-v195.csv has the SHA-256 in PROVENANCE.md . import delimited using "replication/benchmark/REP01-author-R200-v195.csv", clear varnames(1) (encoding automatically selected: UTF-8) (3 vars, 11 obs) . lp_assert "benchmark: REP01-author-R200-v195.csv holds horizons 0 to 10 with rl and rt" : _N == 11 & h == _n - 1 & rl > < . & rt < . pass benchmark: REP01-author-R200-v195.csv holds horizons 0 to 10 with rl and rt . . *========================================================================== . * 5. Files that may or may not be present yet . *========================================================================== . capture confirm file "handoff/l01-explorer-handoff.json" . if _rc == 0 { . lp_json_get using "handoff/l01-explorer-handoff.json", key(lecture) . local v "`r(value)'" . lp_assert "handoff: l01-explorer-handoff.json is a Lecture 01 record" : "`v'" == "01" pass handoff: l01-explorer-handoff.json is a Lecture 01 record . lp_json_get using "handoff/l01-explorer-handoff.json", key(lab3.beta_h) . local n = r(n) . lp_assert "handoff: the record holds thirteen Lab 3 estimates" : `n' == 13 pass handoff: the record holds thirteen Lab 3 estimates . } . else display as text "handoff: no record in handoff/ yet; the Explorer's Transfer to Stata section writes one." . . capture confirm file "data/raw/RZDAT.xlsx" . if _rc == 0 { . lp_sha256 "data/raw/RZDAT.xlsx" . local s "`r(sha256)'" . lp_assert "data: RZDAT.xlsx is the file of the February 2018 package (SHA-256)" : /// > "`s'" == "b2d850872e566ebc6b95a1e057dac2226ef18b58d5a21548594f5ba86c8c6120" pass data: RZDAT.xlsx is the file of the February 2018 package (SHA-256) . import excel using "data/raw/RZDAT.xlsx", sheet("rzdat") firstrow clear (28 vars, 564 obs) . capture confirm numeric variable quarter rgdp rgdp_pott6 pgdp news ngov . local rc = _rc . lp_assert "data: sheet rzdat has quarter, rgdp, rgdp_pott6, pgdp, news, ngov" : `rc' == 0 pass data: sheet rzdat has quarter, rgdp, rgdp_pott6, pgdp, news, ngov . drop if quarter < 1889 (56 observations deleted) . lp_assert "data: 508 quarters from 1889Q1 to 2015Q4" : /// > _N == 508 & abs(quarter[1] - 1889) < 1e-6 & abs(quarter[_N] - 2015.75) < 1e-6 pass data: 508 quarters from 1889Q1 to 2015Q4 . quietly count if news < . . local nn = r(N) . lp_assert "data: news is recorded in 504 of those quarters" : `nn' == 504 pass data: news is recorded in 504 of those quarters . } . else display as text "data: RZDAT.xlsx is not in data/raw yet; Task 5 runs data/raw/get_rz.do to fetch and verify it." . . clear . local npass = $LP_NPASS - `npass0' . display as text _n "Checks complete: " as result `npass' as text " assertions passed." Checks complete: 49 assertions passed. . log close checks name: checks log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/check > s.log log type: text closed on: 13 Sep 2026, 22:46:55 ------------------------------------------------------------------------------------------------------------------------ . end of do-file . . *-------------------------------------------------------------------------- . * 2. Replication lab REP01 . *-------------------------------------------------------------------------- . do "replication/rep01.do" . *! rep01.do REP01 . Recover the basic local-projection estimator . * . * Local Projections: From First Principles to Empirical Research, Practicum 01. . * . * Target Jorda and Taylor (2025), "Local Projections," Journal of Economic . * Literature 63(1), 59-110, Figure 1a: the Monte Carlo mean of the . * levels local projection at h = 0,...,10, with an intercept and . * without the lagged difference. . * Package ojorda/JEL-Code, commit 655696c1c576b7537c5a939d2c261f0a111ae663 . * (CC0), Example1_LongDifferences/SSBias_IntcpYLagdiffN_95.do, . * shipped unchanged in vendor/jel-code/. . * Kind Statistical reproduction. The published figure averages 10,000 . * draws; this file averages $R draws (instructor build 500, student . * default 200; editor decision D2). At a matched draw count the . * reproduction is exact: every mean within 1e-6. . * Mapping vy = s_t (the intervention), e = v_t (the disturbance), . * theta_0 = 1, rho = 0.95, T = 100 after 500 burn-in periods, . * p = 1, so T_h = 99 - h. . * . * Reads replication/benchmark/REP01-levels-lp.csv 500 draws, Stata 18.5 . * replication/benchmark/REP01-author-R200-v195.csv authors' script, 200 draws, StataNow 19.5 . * vendor/jel-code/SSBias_IntcpYLagdiffN_95.dta authors' shipped means, 10,000 draws . * vendor/jel-code/SSBias_IntcpYLagdiffN_95.do run unchanged when AUTHOR_CHECK = 1 . * Writes output/rep01.log, output/rep01-draws.dta, output/rep01-benchmark.csv, . * output/fig-rep01-levels-mean.svg/.png, output/fig-rep01-first-draw.svg/.png . * Globals R number of draws (default 200) . * AUTHOR_CHECK 1 runs the authors' script at the same R (default 1) . * . * Run from the lab project's top folder: do replication/rep01.do . . version 19 . clear . set more off . capture program list lp_assert . if _rc do helpers/lp_helpers.do . lp_root . capture mkdir output . capture log close rep01 . log using "output/rep01.log", text replace name(rep01) (file /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/rep01.log not found) ------------------------------------------------------------------------------------------------------------------------ name: rep01 log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/rep01 > .log log type: text opened on: 13 Sep 2026, 22:46:55 . if "$R" == "" global R 200 . if "$AUTHOR_CHECK" == "" global AUTHOR_CHECK 1 . global LP_STEP rep01 . local R = $R . confirm integer number `R' . timer clear 11 . timer on 11 . local npass0 = cond("$LP_NPASS" == "", 0, $LP_NPASS) . . *========================================================================== . * 0. Settings, with the lines of SSBias_IntcpYLagdiffN_95.do they come from . *========================================================================== . local nobs = 100 // all-simulate.do line 18 . local burn = 500 // line 20 . local tobs = `nobs' + `burn' // line 21 . local hmax = 10 // line 24 . local rho = 0.95 // line 27 . local seed = 12345 // line 39 . display as text _n "REP01: levels LP, rho = `rho', T = `nobs', burn-in `burn', h = 0,...,`hmax', R = `R'" REP01: levels LP, rho = .95, T = 100, burn-in 500, h = 0,...,10, R = 500 . . *========================================================================== . * 1. One realization, one horizon: draw 1 of the authors' loop, rebuilt . * outside the loop . *========================================================================== . clear . set seed `seed' . set obs `tobs' Number of observations (_N) was 0, now 600. . generate t = _n . tsset t Time variable: t, 1 to 600 Delta: 1 unit . generate vy = rnormal() // line 52: the intervention s_t, drawn first . generate y = 0 // line 53: stored as float, as in the authors' code . generate e = rnormal() // line 56: the disturbance v_t, drawn second . * line 59 reads y = $rho*l.y + $a*l.d.y + vy + e if _n > 2, with $a = 0.00 (line 57) . replace y = `rho'*L.y + vy + e if _n > 2 (598 real changes made) . drop if _n <= `burn' // line 62: keep the last 100 periods (500 observations deleted) . replace t = _n (100 real changes made) . tsset t Time variable: t, 1 to 100 Delta: 1 unit . . regress F0.y vy L.y // line 87 at h = 0 Source | SS df MS Number of obs = 99 -------------+---------------------------------- F(2, 96) = 251.99 Model | 501.423656 2 250.711828 Prob > F = 0.0000 Residual | 95.5114248 96 .994910675 R-squared = 0.8400 -------------+---------------------------------- Adj R-squared = 0.8367 Total | 596.93508 98 6.09117429 Root MSE = .99745 ------------------------------------------------------------------------------ y | Coefficient Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- vy | 1.060351 .1026716 10.33 0.000 .8565499 1.264153 | y | L1. | .909107 .0428413 21.22 0.000 .8240676 .9941464 | _cons | .1509078 .1147404 1.32 0.192 -.0768501 .3786656 ------------------------------------------------------------------------------ . lp_assert "REP01 step 1: the h = 0 regression has T_0 = 99 rows" : e(N) == 99 pass REP01 step 1: the h = 0 regression has T_0 = 99 rows . lp_close _b[vy] 1.06035137, tol(1e-6) label(REP01 step 1: draw 1 at h = 0) REP01 step 1: draw 1 at h = 0 value 1.06035143 target 1.06035137 |diff| 5.95e-08 tol 1.0e-06 pass REP01 step 1: draw 1 at h = 0 . . *========================================================================== . * 2. The same draw at every horizon: one regression per point of the curve . *========================================================================== . tempfile draw1 . tempname D . postfile `D' h double b_draw1 T_draw1 using `draw1' . forvalues h = 0/`hmax' { 2. quietly regress F`h'.y vy L.y 3. post `D' (`h') (_b[vy]) (e(N)) 4. } . postclose `D' . preserve . use `draw1', clear . format b_draw1 %12.8f . list, clean noobs h b_draw1 T_draw1 0 1.06035143 99 1 0.99981716 98 2 0.59646150 97 3 0.55573121 96 4 0.40316077 95 5 0.21355944 94 6 0.08826523 93 7 -0.14803844 92 8 -0.28229347 91 9 -0.25071169 90 10 0.24310038 89 . matrix input DRAW1 = (1.06035137, 0.99981713, 0.59646147, 0.55573124, 0.40316078, /// > 0.21355943, 0.08826523, -0.14803843, -0.28229347, -0.25071168, 0.24310037) . lp_assert "REP01 step 2: T_h = 99 - h in draw 1" : T_draw1 == 99 - h pass REP01 step 2: T_h = 99 - h in draw 1 . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. lp_close b_draw1[`i'] DRAW1[1,`i'], tol(1e-6) label(REP01 step 2: draw 1 at h = `h') 4. } REP01 step 2: draw 1 at h = 0 value 1.06035143 target 1.06035137 |diff| 5.95e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 0 REP01 step 2: draw 1 at h = 1 value 0.99981716 target 0.99981713 |diff| 2.89e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 1 REP01 step 2: draw 1 at h = 2 value 0.59646150 target 0.59646147 |diff| 2.94e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 2 REP01 step 2: draw 1 at h = 3 value 0.55573121 target 0.55573124 |diff| 2.53e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 3 REP01 step 2: draw 1 at h = 4 value 0.40316077 target 0.40316078 |diff| 9.07e-09 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 4 REP01 step 2: draw 1 at h = 5 value 0.21355944 target 0.21355943 |diff| 1.04e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 5 REP01 step 2: draw 1 at h = 6 value 0.08826523 target 0.08826523 |diff| 9.84e-10 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 6 REP01 step 2: draw 1 at h = 7 value -0.14803844 target -0.14803843 |diff| 6.90e-09 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 7 REP01 step 2: draw 1 at h = 8 value -0.28229347 target -0.28229347 |diff| 4.16e-09 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 8 REP01 step 2: draw 1 at h = 9 value -0.25071169 target -0.25071168 |diff| 1.04e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 9 REP01 step 2: draw 1 at h = 10 value 0.24310038 target 0.24310037 |diff| 1.20e-08 tol 1.0e-06 pass REP01 step 2: draw 1 at h = 10 . restore . . *========================================================================== . * 3. The Monte Carlo: R draws from one seeded stream (line 39), the levels . * LP at h = 0,...,10 in each (lines 84-90) . *========================================================================== . display as text _n "Monte Carlo with R = `R' draws ..." Monte Carlo with R = 500 draws ... . timer clear 12 . timer on 12 . tempname M . postfile `M' rep h double b T_h using "output/rep01-draws.dta", replace (file output/rep01-draws.dta not found) . set seed `seed' . quietly forvalues r = 1/`R' { . postclose `M' . timer off 12 . quietly timer list 12 . local mc_seconds = r(t12) . display as text "Monte Carlo runtime: " as result %8.2f `mc_seconds' as text " seconds for R = `R'" Monte Carlo runtime: 15.10 seconds for R = 500 . . use "output/rep01-draws.dta", clear . lp_assert "REP01: every draw has T_h = 99 - h rows" : T_h == 99 - h pass REP01: every draw has T_h = 99 - h rows . lp_assert "REP01: R draws at each of 11 horizons" : _N == 11*`R' pass REP01: R draws at each of 11 horizons . . *-------------------------------------------------------------------------- . * 4. Means over all R draws, and over the first 200 and 500 draws, which are . * the matched counts of the two exact benchmarks . *-------------------------------------------------------------------------- . preserve . collapse (mean) mean_R=b (sd) sd_R=b (p5) p5_R=b (p95) p95_R=b (count) draws=b, by(h) . tempfile summary . save `summary' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000004 saved as .dta format . restore . foreach m in 200 500 { 2. tempfile sum`m' 3. preserve 4. if `R' >= `m' { 5. keep if rep <= `m' 6. collapse (mean) mean_`m'=b, by(h) 7. } 8. else { 9. keep if rep == 1 10. keep h 11. generate double mean_`m' = . 12. } 13. save `sum`m'' 14. restore 15. } (3,300 observations deleted) file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000005 saved as .dta format (0 observations deleted) file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000007 saved as .dta format . . import delimited using "replication/benchmark/REP01-levels-lp.csv", clear varnames(1) encoding(utf8) (21 vars, 11 obs) . lp_assert "REP01 benchmark file: 11 rows of the levels series" : _N == 11 & series == "levels" pass REP01 benchmark file: 11 rows of the levels series . keep horizon coefficient true_response n . rename (horizon coefficient true_response n) (h published_500 published_theta published_T_h) . tempfile bench . save `bench' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000009 saved as .dta format . . import delimited using "replication/benchmark/REP01-author-R200-v195.csv", clear varnames(1) (encoding automatically selected: UTF-8) (3 vars, 11 obs) . rename (rl rt) (author_200 author_theta_200) . tempfile author200 . save `author200' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.00000a saved as .dta format . . use "vendor/jel-code/SSBias_IntcpYLagdiffN_95.dta", clear . keep t rl rt . rename (t rl rt) (h author_10000 author_theta) . tempfile author10000 . save `author10000' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.00000b saved as .dta format . . use `summary', clear . foreach f in sum200 sum500 bench author200 author10000 { 2. merge 1:1 h using ``f'', nogenerate assert(match) 3. } Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- . generate double theta_h = `rho'^h . generate T_h = 99 - h . generate double mcse_R = sd_R/sqrt(`R') . generate double diff_500 = mean_500 - published_500 . generate double diff_200 = mean_200 - author_200 . generate double se_10000 = sd_R*sqrt(1/`R' + 1/10000) . generate double z_10000 = (mean_R - author_10000)/se_10000 . generate double se_500 = sd_R*sqrt(abs(1/`R' - 1/500)) . generate double z_500 = cond(`R' == 500, 0, (mean_R - published_500)/se_500) . . format theta_h published_500 mean_500 diff_500 author_200 mean_200 diff_200 author_10000 mean_R sd_R mcse_R %11.8f . format z_10000 z_500 %6.2f . display as text _n "REP01 comparison by horizon" REP01 comparison by horizon . list h T_h theta_h published_500 mean_500 diff_500 author_200 mean_200 diff_200, clean noobs h T_h theta_h publis~500 mean_500 diff_500 author_200 mean_200 diff_200 0 99 1.00000000 1.00175750 1.00175746 -0.00000004 0.99686521 0.99686519 -0.00000003 1 98 0.95000000 0.92489529 0.92489526 -0.00000002 0.91357774 0.91357771 -0.00000003 2 97 0.90250000 0.86787397 0.86787396 -0.00000001 0.85901380 0.85901381 0.00000002 3 96 0.85737500 0.79257834 0.79257836 0.00000002 0.78925842 0.78925840 -0.00000002 4 95 0.81450625 0.73754936 0.73754938 0.00000002 0.74316418 0.74316419 0.00000000 5 94 0.77378094 0.67800373 0.67800374 0.00000001 0.68870902 0.68870901 -0.00000001 6 93 0.73509189 0.62550861 0.62550860 -0.00000000 0.62830913 0.62830915 0.00000002 7 92 0.69833730 0.57830870 0.57830868 -0.00000002 0.57235688 0.57235686 -0.00000002 8 91 0.66342043 0.51882571 0.51882570 -0.00000001 0.50967115 0.50967116 0.00000001 9 90 0.63024941 0.48049915 0.48049915 0.00000000 0.48197576 0.48197576 0.00000000 10 89 0.59873694 0.43152007 0.43152008 0.00000001 0.42771590 0.42771590 -0.00000000 . list h author_10000 mean_R sd_R mcse_R z_10000 z_500, clean noobs h auth~10000 mean_R sd_R mcse_R z_10000 z_500 0 0.99697095 1.00175746 0.10465395 0.00468027 1.00 0.00 1 0.92157829 0.92489526 0.17283519 0.00772942 0.42 0.00 2 0.84994626 0.86787396 0.22938530 0.01025842 1.71 0.00 3 0.78295529 0.79257836 0.26442179 0.01182530 0.79 0.00 4 0.72164255 0.73754938 0.30159171 0.01348759 1.15 0.00 5 0.66630644 0.67800374 0.33255860 0.01487247 0.77 0.00 6 0.61206740 0.62550860 0.35454376 0.01585568 0.83 0.00 7 0.56319672 0.57830868 0.37134603 0.01660710 0.89 0.00 8 0.51815391 0.51882570 0.39521070 0.01767436 0.04 0.00 9 0.47492251 0.48049915 0.39662619 0.01773766 0.31 0.00 10 0.42890212 0.43152008 0.39692485 0.01775102 0.14 0.00 . . *-------------------------------------------------------------------------- . * 5. Assertions against the benchmarks . *-------------------------------------------------------------------------- . lp_assert "REP01: the benchmark's derived row count is T_h = 99 - h" : published_T_h == 99 - h pass REP01: the benchmark's derived row count is T_h = 99 - h . lp_assert "REP01: the true response equals the authors' rt (1e-6)" : abs(author_theta - theta_h) < 1e-6 pass REP01: the true response equals the authors' rt (1e-6) . lp_assert "REP01: the true response equals the benchmark's true_response (1e-6)" : abs(published_theta - theta_h) < 1e > -6 pass REP01: the true response equals the benchmark's true_response (1e-6) . . if `R' >= 500 { . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. lp_close mean_500[`i'] published_500[`i'], tol(1e-6) /// > label(REP01 exact: first 500 draws against the published benchmark at h = `h') 4. } REP01 exact: first 500 draws against the published benchmark at h = 0 value 1.00175746 target 1.00175750 |diff| 4.02e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 0 REP01 exact: first 500 draws against the published benchmark at h = 1 value 0.92489526 target 0.92489529 |diff| 2.40e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 1 REP01 exact: first 500 draws against the published benchmark at h = 2 value 0.86787396 target 0.86787397 |diff| 1.06e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 2 REP01 exact: first 500 draws against the published benchmark at h = 3 value 0.79257836 target 0.79257834 |diff| 2.22e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 3 REP01 exact: first 500 draws against the published benchmark at h = 4 value 0.73754938 target 0.73754936 |diff| 1.84e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 4 REP01 exact: first 500 draws against the published benchmark at h = 5 value 0.67800374 target 0.67800373 |diff| 8.83e-09 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 5 REP01 exact: first 500 draws against the published benchmark at h = 6 value 0.62550860 target 0.62550861 |diff| 2.99e-09 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 6 REP01 exact: first 500 draws against the published benchmark at h = 7 value 0.57830868 target 0.57830870 |diff| 2.02e-08 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 7 REP01 exact: first 500 draws against the published benchmark at h = 8 value 0.51882570 target 0.51882571 |diff| 8.14e-09 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 8 REP01 exact: first 500 draws against the published benchmark at h = 9 value 0.48049915 target 0.48049915 |diff| 1.40e-09 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 9 REP01 exact: first 500 draws against the published benchmark at h = 10 value 0.43152008 target 0.43152007 |diff| 7.71e-09 tol 1.0e-06 pass REP01 exact: first 500 draws against the published benchmark at h = 10 . } . else display as text "Fewer than 500 draws: the exact comparison with the 500-draw benchmark is skipped." . . if `R' >= 200 { . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. lp_close mean_200[`i'] author_200[`i'], tol(1e-6) /// > label(REP01 exact: first 200 draws against the authors' script at 200 draws at h = `h') 4. } REP01 exact: first 200 draws against the authors' script at 200 draws at h = 0 value 0.99686519 target 0.99686521 |diff| 2.58e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 0 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 1 value 0.91357771 target 0.91357774 |diff| 2.69e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 1 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 2 value 0.85901381 target 0.85901380 |diff| 1.54e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 2 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 3 value 0.78925840 target 0.78925842 |diff| 2.21e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 3 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 4 value 0.74316419 target 0.74316418 |diff| 3.31e-09 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 4 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 5 value 0.68870901 target 0.68870902 |diff| 1.19e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 5 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 6 value 0.62830915 target 0.62830913 |diff| 1.99e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 6 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 7 value 0.57235686 target 0.57235688 |diff| 2.28e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 7 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 8 value 0.50967116 target 0.50967115 |diff| 1.17e-08 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 8 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 9 value 0.48197576 target 0.48197576 |diff| 4.29e-10 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 9 REP01 exact: first 200 draws against the authors' script at 200 draws at h = 10 value 0.42771590 target 0.42771590 |diff| 6.81e-10 tol 1.0e-06 pass REP01 exact: first 200 draws against the authors' script at 200 draws at h = 10 . } . else display as text "Fewer than 200 draws: the exact comparison with the 200-draw run is skipped." . . * Statistical comparisons. The published figure's 10,000 draws are treated as . * an independent stream, which gives the wider of the two possible bounds. . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. local z = z_10000[`i'] 4. lp_assert "REP01 statistical: mean of `R' draws within 3 Monte Carlo SE of the 10,000-draw mean at h = `h' (z = > `: display %5.2f `z'')" : abs(`z') < 3 5. } pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 0 (z = 1.00) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 1 (z = 0.42) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 2 (z = 1.71) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 3 (z = 0.79) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 4 (z = 1.15) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 5 (z = 0.77) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 6 (z = 0.83) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 7 (z = 0.89) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 8 (z = 0.04) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 9 (z = 0.31) pass REP01 statistical: mean of 500 draws within 3 Monte Carlo SE of the 10,000-draw mean at h = 10 (z = 0.14) . if `R' != 500 { . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. local z = z_500[`i'] 4. lp_assert "REP01 statistical: mean of `R' draws within 3 nested Monte Carlo SE of the 500-draw benchmark at > h = `h' (z = `: display %5.2f `z'')" : abs(`z') < 3 5. } . } . tempfile results . save `results' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.00000c saved as .dta format . . *-------------------------------------------------------------------------- . * 6. Cross-check: the authors' script, unchanged, at the same number of draws . *-------------------------------------------------------------------------- . local author_seconds = . . if "$AUTHOR_CHECK" == "1" { . save `results', replace file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.00000c saved as .dta format . local here = c(pwd) . capture mkdir "output/rep01-author" . quietly cd "output/rep01-author" . global nobs = `nobs' . global nreps = `R' . display as text _n "Running vendor/jel-code/SSBias_IntcpYLagdiffN_95.do with nreps = `R' (progress counter follows > )" Running vendor/jel-code/SSBias_IntcpYLagdiffN_95.do with nreps = 500 (progress counter follows) . timer clear 13 . timer on 13 . capture noisily quietly do "`here'/vendor/jel-code/SSBias_IntcpYLagdiffN_95.do" . local rc = _rc . timer off 13 . quietly cd "`here'" . if `rc' { . display as error "The authors' script stopped with r(`rc')." . exit `rc' . } . quietly timer list 13 . local author_seconds = r(t13) . display as text _n "Authors' script runtime: " as result %8.2f `author_seconds' as text " seconds" Authors' script runtime: 46.39 seconds . keep t rl rt . rename (t rl rt) (h author_script_R author_script_theta) . merge 1:1 h using `results', nogenerate assert(match) Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- . sort h . forvalues h = 0/`hmax' { 2. local i = `h' + 1 3. lp_close author_script_R[`i'] mean_R[`i'], tol(1e-6) /// > label(REP01 cross-check: authors' script against this file at R = `R' and h = `h') 4. } REP01 cross-check: authors' script against this file at R = 500 and h = 0 value 1.00175750 target 1.00175746 |diff| 4.02e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 0 REP01 cross-check: authors' script against this file at R = 500 and h = 1 value 0.92489529 target 0.92489526 |diff| 2.40e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 1 REP01 cross-check: authors' script against this file at R = 500 and h = 2 value 0.86787397 target 0.86787396 |diff| 1.06e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 2 REP01 cross-check: authors' script against this file at R = 500 and h = 3 value 0.79257834 target 0.79257836 |diff| 2.22e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 3 REP01 cross-check: authors' script against this file at R = 500 and h = 4 value 0.73754936 target 0.73754938 |diff| 1.84e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 4 REP01 cross-check: authors' script against this file at R = 500 and h = 5 value 0.67800373 target 0.67800374 |diff| 8.83e-09 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 5 REP01 cross-check: authors' script against this file at R = 500 and h = 6 value 0.62550861 target 0.62550860 |diff| 2.99e-09 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 6 REP01 cross-check: authors' script against this file at R = 500 and h = 7 value 0.57830870 target 0.57830868 |diff| 2.02e-08 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 7 REP01 cross-check: authors' script against this file at R = 500 and h = 8 value 0.51882571 target 0.51882570 |diff| 8.14e-09 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 8 REP01 cross-check: authors' script against this file at R = 500 and h = 9 value 0.48049915 target 0.48049915 |diff| 1.40e-09 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 9 REP01 cross-check: authors' script against this file at R = 500 and h = 10 value 0.43152007 target 0.43152008 |diff| 7.71e-09 tol 1.0e-06 pass REP01 cross-check: authors' script against this file at R = 500 and h = 10 . lp_assert "REP01 cross-check: the authors' true response equals 0.95^h (1e-6)" : abs(author_script_theta - theta_h > ) < 1e-6 pass REP01 cross-check: the authors' true response equals 0.95^h (1e-6) . macro drop nobs nreps burn tobs hmax rho a . } . else { . display as text "AUTHOR_CHECK = 0: the authors' script was not run." . generate double author_script_R = . . } . generate double diff_author = author_script_R - mean_R . sort h . . *-------------------------------------------------------------------------- . * 7. The benchmark record, one row per horizon . *-------------------------------------------------------------------------- . tempname B . postfile `B' h T_h double(theta_h published_R500 reproduced_R500 diff_R500 /// > author_R200_v195 reproduced_R200 diff_R200 author_R10000 reproduced_R /// > sd_R mcse_R z_vs_R10000 author_script diff_author_script) draws /// > double tolerance using "output/rep01-benchmark.dta", replace (file output/rep01-benchmark.dta not found) . forvalues i = 1/11 { 2. post `B' (h[`i']) (T_h[`i']) (theta_h[`i']) (published_500[`i']) /// > (mean_500[`i']) (diff_500[`i']) (author_200[`i']) (mean_200[`i']) /// > (diff_200[`i']) (author_10000[`i']) (mean_R[`i']) (sd_R[`i']) /// > (mcse_R[`i']) (z_10000[`i']) (author_script_R[`i']) (diff_author[`i']) /// > (`R') (1e-6) 3. } . postclose `B' . preserve . use "output/rep01-benchmark.dta", clear . format theta_h-diff_author_script %12.8f . export delimited using "output/rep01-benchmark.csv", replace datafmt (file output/rep01-benchmark.csv not found) file output/rep01-benchmark.csv saved . restore . . *-------------------------------------------------------------------------- . * 8. Figures . *-------------------------------------------------------------------------- . set scheme stcolor . merge 1:1 h using `draw1', nogenerate assert(match) Result Number of obs ----------------------------------------- Not matched 0 Matched 11 ----------------------------------------- . local ink "82 81 78" . local muted "137 135 129" . local blue "42 120 214" . local orange "217 96 31" . local rule "195 194 183" . . twoway (line theta_h h, lcolor("`ink'") lwidth(medthick)) /// > (line author_10000 h, lcolor("`muted'") lpattern(dash) lwidth(medium)) /// > (scatter published_500 h, msymbol(Oh) mcolor("`orange'") msize(large) mlwidth(medthick)) /// > (connected mean_R h, lcolor("`blue'") mcolor("`blue'") msymbol(O) msize(small) lwidth(medthick)), /// > xlabel(0(1)10, nogrid) /// > ylabel(0.4(0.1)1.0, format(%3.1f) angle(0) glcolor("`rule'") glpattern(solid) glwidth(vthin)) /// > xtitle("Horizon h (periods after the intervention)") /// > ytitle("Mean of the estimate across draws") /// > legend(order(1 "True response 0.95{sup:h}" /// > 2 "Authors' shipped mean, 10,000 draws" /// > 3 "Course benchmark, 500 draws (Stata 18.5)" /// > 4 "This run, `R' draws (StataNow 19.5)") /// > cols(1) position(1) ring(0) region(lstyle(none) fcolor(white)) size(small)) /// > graphregion(color(white)) plotregion(color(white)) xsize(6.5) ysize(4.2) . graph export "output/fig-rep01-levels-mean.svg", replace (file output/fig-rep01-levels-mean.svg not found) file output/fig-rep01-levels-mean.svg saved as SVG format . graph export "output/fig-rep01-levels-mean.png", replace width(1950) (file output/fig-rep01-levels-mean.png not found) file output/fig-rep01-levels-mean.png written in PNG format . . twoway (rarea p5_R p95_R h, color("`blue'%15") lwidth(none)) /// > (line theta_h h, lcolor("`ink'") lwidth(medthick)) /// > (connected mean_R h, lcolor("`blue'") mcolor("`blue'") msymbol(O) msize(small) lwidth(medthick)) /// > (connected b_draw1 h, lcolor("`orange'") mcolor("`orange'") msymbol(D) msize(small) lwidth(medium)), /// > yline(0, lcolor("`rule'")) xlabel(0(1)10, nogrid) /// > ylabel(-0.4(0.2)1.4, format(%3.1f) angle(0) glcolor("`rule'") glpattern(solid) glwidth(vthin)) /// > xtitle("Horizon h (periods after the intervention)") /// > ytitle("Estimate (units of y per unit of s)") /// > legend(order(2 "True response 0.95{sup:h}" 3 "Mean of `R' draws" /// > 4 "Draw 1 (seed 12345)" 1 "Middle 90 percent of the `R' draws") /// > cols(2) position(6) region(lstyle(none)) size(small)) /// > graphregion(color(white)) plotregion(color(white)) xsize(6.5) ysize(4.4) . graph export "output/fig-rep01-first-draw.svg", replace (file output/fig-rep01-first-draw.svg not found) file output/fig-rep01-first-draw.svg saved as SVG format . graph export "output/fig-rep01-first-draw.png", replace width(1950) (file output/fig-rep01-first-draw.png not found) file output/fig-rep01-first-draw.png written in PNG format . . *-------------------------------------------------------------------------- . timer off 11 . quietly timer list 11 . local total_seconds = r(t11) . local npass = $LP_NPASS - `npass0' . display as text _n "REP01 complete: " as result `npass' as text " assertions passed; R = `R'; Monte Carlo " /// > as result %7.2f `mc_seconds' as text " s; authors' script " as result %7.2f `author_seconds' /// > as text " s; total " as result %7.2f `total_seconds' as text " s" REP01 complete: 65 assertions passed; R = 500; Monte Carlo 15.10 s; authors' script 46.39 s; total 63.71 s . log close rep01 name: rep01 log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/rep01 > .log log type: text closed on: 13 Sep 2026, 22:47:59 ------------------------------------------------------------------------------------------------------------------------ . end of do-file . . *-------------------------------------------------------------------------- . * 3. Stata problem set STA01 . *-------------------------------------------------------------------------- . if "`mode'" == "solution" { . display as text _n "Running solution/pset_solution.do. Its commands and written answers go only to" Running solution/pset_solution.do. Its commands and written answers go only to . display as text "output/pset/pset.log; the checks it passes are listed in output/assertions.csv." output/pset/pset.log; the checks it passes are listed in output/assertions.csv. . local npass_before = $LP_NPASS . log off master name: master log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/maste > r.log log type: text paused on: 13 Sep 2026, 22:47:59 ------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------ name: master log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/maste > r.log log type: text resumed on: 13 Sep 2026, 22:49:11 . if `rc' { . display as error "solution/pset_solution.do stopped with r(`rc'); see output/pset/pset.log." . exit `rc' . } . display as text "STA01 instructor solution: " as result $LP_NPASS - `npass_before' as text " assertions passed." STA01 instructor solution: 48 assertions passed. . } . else { . do "starter/pset.do" . } . . *-------------------------------------------------------------------------- . * 4. The Explorer's handoff record, rerun in Stata . *-------------------------------------------------------------------------- . do "handoff/check_handoff.do" . *! check_handoff.do Check the Shock-to-Response Explorer's handoff record in Stata . * . * Local Projections: From First Principles to Empirical Research, Practicum 01. . * . * The "Transfer to Stata" section of the Explorer writes three files: . * l01-explorer-handoff.json, hand_table.csv, and the draw file chosen in Lab 3 . * (onedraw_rho09_seed2.csv or onedraw_rho05_seed2.csv). Put them in this . * folder. A sample record, written by the Explorer's own code with the . * settings listed in handoff/README.md, ships with the project; your record . * replaces it. . * . * For each lab this file reruns in Stata what the browser computed: . * Lab 2 the rows and the slope for the recorded h, control, and . * single-episode setting (row count exact, slope within 1e-6) . * Lab 3 thirteen row counts and slopes for the recorded draw, T, and . * control (within 1e-6) . * Lab 4 the stored coefficient for the recorded h, controls, and rows, . * re-estimated from RZDAT.xlsx when data/raw holds a verified copy . * (Task 5 of the problem set downloads it), and the written . * hypothesis set beside the estimate . * . * Writes output/handoff-check.log and output/handoff-check.csv. . * Run from the lab project's top folder: do handoff/check_handoff.do . . version 19 . clear . set more off . capture program list lp_assert . if _rc do helpers/lp_helpers.do . lp_root . capture mkdir output . capture log close handoff . log using "output/handoff-check.log", text replace name(handoff) (file /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/handoff-chec > k.log not found) ------------------------------------------------------------------------------------------------------------------------ name: handoff log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/hando > ff-check.log log type: text opened on: 13 Sep 2026, 22:49:11 . global LP_STEP handoff . . local rec "handoff/l01-explorer-handoff.json" . capture confirm file "`rec'" . if _rc { . display as text "No handoff record in handoff/. Download l01-explorer-handoff.json from the Explorer to check it." . log close handoff . exit . } . . tempname T . postfile `T' str6 lab str44 quantity double(browser stata difference) str44 result /// > using "output/handoff-check.dta", replace (file output/handoff-check.dta not found) . . * A value of null in the record means the browser had no finite number. . capture program drop _lp_num . program define _lp_num, rclass 1. args text 2. if inlist(`"`text'"', "", "null") return scalar x = . 3. else return scalar x = `text' 4. end . . lp_json_get using "`rec'", key(lecture) . local lecture "`r(value)'" . lp_assert "Handoff: the record comes from the Lecture 01 Explorer" : "`lecture'" == "01" pass Handoff: the record comes from the Lecture 01 Explorer . . *========================================================================== . * Lab 2: the rows of the horizon-h regression in the hand table . *========================================================================== . lp_json_get using "`rec'", key(lab2.settings.h) . local h2 = `r(value)' . lp_json_get using "`rec'", key(lab2.settings.control_y_lag) . local ctl2 = ("`r(value)'" == "true") . lp_json_get using "`rec'", key(lab2.settings.single_episode) . local one2 = ("`r(value)'" == "true") . lp_json_get using "`rec'", key(lab2.T_h) . local Th2 = `r(value)' . lp_json_get using "`rec'", key(lab2.beta_h) . _lp_num "`r(value)'" . local b2 = r(x) . display as text _n "Lab 2 record: h = `h2', control = `ctl2', single episode = `one2', T_h = `Th2', slope = `b2'" Lab 2 record: h = 2, control = 0, single episode = 0, T_h = 9, slope = 2.050024 . . local hand "data/raw/hand_table.csv" . capture confirm file "handoff/hand_table.csv" . if _rc == 0 { . import delimited using "handoff/hand_table.csv", clear (encoding automatically selected: ISO-8859-2) (4 vars, 12 obs) . rename (s v y) (s_b v_b y_b) . tempfile browser . save `browser' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000001 saved as .dta format . import delimited using "data/raw/hand_table.csv", clear (encoding automatically selected: ISO-8859-2) (4 vars, 12 obs) . merge 1:1 t using `browser', nogenerate Result Number of obs ----------------------------------------- Not matched 0 Matched 12 ----------------------------------------- . lp_assert "Handoff Lab 2: handoff/hand_table.csv holds the shipped observations" : /// > abs(s - s_b) < 1e-7 & abs(v - v_b) < 1e-7 & abs(y - y_b) < 1e-7 pass Handoff Lab 2: handoff/hand_table.csv holds the shipped observations . lp_sha256 "handoff/hand_table.csv" . local sha_b "`r(sha256)'" . lp_sha256 "data/raw/hand_table.csv" . display as text "SHA-256 of the browser export " cond("`sha_b'" == "`r(sha256)'", "equals", "differs from") " the > shipped file." SHA-256 of the browser export equals the shipped file. . local hand "handoff/hand_table.csv" . } . import delimited using "`hand'", clear (encoding automatically selected: ISO-8859-2) (4 vars, 12 obs) . tsset t Time variable: t, 1 to 12 Delta: 1 unit . local regressor "s" . if `one2' { . generate byte s_one = (t == 5) . local regressor "s_one" . } . local control = cond(`ctl2', "L.y", "") . display as text "regress F`h2'.y `regressor' `control' if t >= 2" regress F2.y s if t >= 2 . regress F`h2'.y `regressor' `control' if t >= 2 Source | SS df MS Number of obs = 9 -------------+---------------------------------- F(1, 7) = 10.27 Model | 6.53737764 1 6.53737764 Prob > F = 0.0150 Residual | 4.45472039 7 .636388627 R-squared = 0.5947 -------------+---------------------------------- Adj R-squared = 0.5368 Total | 10.992098 8 1.37401225 Root MSE = .79774 ------------------------------------------------------------------------------ F2.y | Coefficient Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- s | 2.050024 .6396147 3.21 0.015 .5375759 3.562473 _cons | .2325195 .3015173 0.77 0.466 -.4804555 .9454946 ------------------------------------------------------------------------------ . lp_assert "Handoff Lab 2: `Th2' rows at h = `h2', as in the browser" : e(N) == `Th2' pass Handoff Lab 2: 9 rows at h = 2, as in the browser . local b2s = _b[`regressor'] . lp_close `b2s' `b2', tol(1e-6) label(Handoff Lab 2: the slope at h = `h2' against the browser) Handoff Lab 2: the slope at h = 2 against the browser value 2.05002437 target 2.05002400 |diff| 3.69e-07 tol 1.0e-06 pass Handoff Lab 2: the slope at h = 2 against the browser . post `T' ("Lab 2") ("slope at h = `h2'") (`b2') (`b2s') (`b2s' - `b2') ("agrees within 1e-6") . . *========================================================================== . * Lab 3: thirteen local projections on the recorded draw . *========================================================================== . lp_json_get using "`rec'", key(lab3.settings.rho) . local rho3 "`r(value)'" . lp_json_get using "`rec'", key(lab3.settings.T) . local T3 = `r(value)' . lp_json_get using "`rec'", key(lab3.settings.control_y_lag) . local ctl3 = ("`r(value)'" == "true") . lp_json_get using "`rec'", key(lab3.file) . local file3 "`r(value)'" . lp_json_get using "`rec'", key(lab3.beta_h) . local b3 "`r(value)'" . local nb3 = r(n) . lp_json_get using "`rec'", key(lab3.T_h) . local n3 "`r(value)'" . display as text _n "Lab 3 record: rho = `rho3', T = `T3', control = `ctl3', file `file3'" Lab 3 record: rho = 0.9, T = 200, control = 1, file onedraw_rho09_seed2.csv . lp_assert "Handoff Lab 3: the record names one of the two shipped draws" : /// > inlist("`file3'", "onedraw_rho09_seed2.csv", "onedraw_rho05_seed2.csv") pass Handoff Lab 3: the record names one of the two shipped draws . lp_assert "Handoff Lab 3: thirteen browser estimates" : `nb3' == 13 pass Handoff Lab 3: thirteen browser estimates . . local draw "data/raw/`file3'" . capture confirm file "handoff/`file3'" . if _rc == 0 { . import delimited using "handoff/`file3'", clear (encoding automatically selected: ISO-8859-2) (4 vars, 200 obs) . rename (s v y) (s_b v_b y_b) . tempfile browser . save `browser' file /var/folders/bk/6srdc2qx62b56c7594wqt1yw0000gn/T//St53173.000002 saved as .dta format . import delimited using "data/raw/`file3'", clear (encoding automatically selected: ISO-8859-2) (4 vars, 200 obs) . merge 1:1 t using `browser', nogenerate Result Number of obs ----------------------------------------- Not matched 0 Matched 200 ----------------------------------------- . lp_assert "Handoff Lab 3: handoff/`file3' holds the shipped observations" : /// > abs(s - s_b) < 1e-7 & abs(v - v_b) < 1e-7 & abs(y - y_b) < 1e-7 pass Handoff Lab 3: handoff/onedraw_rho09_seed2.csv holds the shipped observations . local draw "handoff/`file3'" . } . import delimited using "`draw'", clear (encoding automatically selected: ISO-8859-2) (4 vars, 200 obs) . tsset t Time variable: t, 1 to 200 Delta: 1 unit . keep if t <= `T3' (0 observations deleted) . local control = cond(`ctl3', "L.y", "") . forvalues h = 0/12 { 2. local i = `h' + 1 3. local bb : word `i' of `b3' 4. local nn : word `i' of `n3' 5. _lp_num "`bb'" 6. local bb = r(x) 7. quietly regress F`h'.y s `control' 8. lp_assert "Handoff Lab 3: `nn' rows at h = `h'" : e(N) == `nn' 9. local bs = _b[s] 10. lp_close `bs' `bb', tol(1e-6) label(Handoff Lab 3: the slope at h = `h' against the browser) 11. post `T' ("Lab 3") ("slope at h = `h'") (`bb') (`bs') (`bs' - `bb') ("agrees within 1e-6") 12. } pass Handoff Lab 3: 199 rows at h = 0 Handoff Lab 3: the slope at h = 0 against the browser value 0.87894028 target 0.87894000 |diff| 2.81e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 0 against the browser pass Handoff Lab 3: 198 rows at h = 1 Handoff Lab 3: the slope at h = 1 against the browser value 0.85326038 target 0.85326000 |diff| 3.78e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 1 against the browser pass Handoff Lab 3: 197 rows at h = 2 Handoff Lab 3: the slope at h = 2 against the browser value 0.61273705 target 0.61273700 |diff| 4.55e-08 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 2 against the browser pass Handoff Lab 3: 196 rows at h = 3 Handoff Lab 3: the slope at h = 3 against the browser value 0.61104632 target 0.61104600 |diff| 3.24e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 3 against the browser pass Handoff Lab 3: 195 rows at h = 4 Handoff Lab 3: the slope at h = 4 against the browser value 0.54847739 target 0.54847700 |diff| 3.93e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 4 against the browser pass Handoff Lab 3: 194 rows at h = 5 Handoff Lab 3: the slope at h = 5 against the browser value 0.58309851 target 0.58309900 |diff| 4.90e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 5 against the browser pass Handoff Lab 3: 193 rows at h = 6 Handoff Lab 3: the slope at h = 6 against the browser value 0.50912038 target 0.50912000 |diff| 3.77e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 6 against the browser pass Handoff Lab 3: 192 rows at h = 7 Handoff Lab 3: the slope at h = 7 against the browser value 0.41778779 target 0.41778800 |diff| 2.13e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 7 against the browser pass Handoff Lab 3: 191 rows at h = 8 Handoff Lab 3: the slope at h = 8 against the browser value 0.24059456 target 0.24059500 |diff| 4.41e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 8 against the browser pass Handoff Lab 3: 190 rows at h = 9 Handoff Lab 3: the slope at h = 9 against the browser value 0.13029288 target 0.13029300 |diff| 1.22e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 9 against the browser pass Handoff Lab 3: 189 rows at h = 10 Handoff Lab 3: the slope at h = 10 against the browser value -0.02882139 target -0.02882100 |diff| 3.95e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 10 against the browser pass Handoff Lab 3: 188 rows at h = 11 Handoff Lab 3: the slope at h = 11 against the browser value -0.11719967 target -0.11720000 |diff| 3.30e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 11 against the browser pass Handoff Lab 3: 187 rows at h = 12 Handoff Lab 3: the slope at h = 12 against the browser value -0.29329663 target -0.29329700 |diff| 3.66e-07 tol 1.0e-06 pass Handoff Lab 3: the slope at h = 12 against the browser . . *========================================================================== . * Lab 4: the stored military-news estimate and the written hypothesis . *========================================================================== . lp_json_get using "`rec'", key(lab4.settings.h) . local h4 = `r(value)' . lp_json_get using "`rec'", key(lab4.settings.controls) . local spec4 "`r(value)'" . lp_json_get using "`rec'", key(lab4.settings.rows) . local rows4 "`r(value)'" . lp_json_get using "`rec'", key(lab4.stored.beta_h) . _lp_num "`r(value)'" . local b4 = r(x) . lp_json_get using "`rec'", key(lab4.stored.T_h) . local n4 = `r(value)' . lp_json_get using "`rec'", key(lab4.stored.beta_h_full_sample) . _lp_num "`r(value)'" . local b4full = r(x) . lp_json_get using "`rec'", key(lab4.stored.T_h_full_sample) . local n4full = `r(value)' . display as text _n "Lab 4 record: h = `h4', controls `spec4', rows `rows4'; stored estimate `b4' on `n4' rows" Lab 4 record: h = 8, controls toy, rows drop1950q3; stored estimate .433969 on 495 rows . display as text "Written hypothesis:" Written hypothesis: . lp_json_get using "`rec'", key(lab4.hypothesis) display Sample record. Dropping 1950Q3 will lower the h = 8 coefficient to about 0.30, because Korea is one of the two largest n > ews quarters. . local dir4 "`r(direction)'" . local num4 "`r(number)'" . lp_assert "Handoff Lab 4: recognized controls and rows" : /// > inlist("`spec4'", "toy", "rz") & inlist("`rows4'", "full", "drop1941q4", "drop1950q3", "dropboth", "from1947q1") pass Handoff Lab 4: recognized controls and rows . . local rz_ok 0 . capture confirm file "data/raw/RZDAT.xlsx" . if _rc == 0 { . lp_sha256 "data/raw/RZDAT.xlsx" . if "`r(sha256)'" == "b2d850872e566ebc6b95a1e057dac2226ef18b58d5a21548594f5ba86c8c6120" local rz_ok 1 . } . if !`rz_ok' { . display as text "Lab 4 re-estimation skipped: data/raw has no verified RZDAT.xlsx. Run do data/raw/get_rz.do fir > st." . post `T' ("Lab 4") ("estimate at h = `h4'") (`b4') (.) (.) ("skipped: RZDAT.xlsx not acquired") . } . else { . import excel using "data/raw/RZDAT.xlsx", sheet("rzdat") firstrow clear (28 vars, 564 obs) . drop if quarter < 1889 (56 observations deleted) . generate qdate = yq(1889, 1) + _n - 1 . format qdate %tq . tsset qdate, quarterly Time variable: qdate, 1889q1 to 2015q4 Delta: 1 quarter . generate double y = rgdp/rgdp_pott6 // real GDP / trend GDP . generate double g = (ngov/pgdp)/rgdp_pott6 // real government spending / trend GDP . generate double newsy = news/(L.rgdp_pott6*L.pgdp) // news / lagged nominal trend GDP (4 missing values generated) . local control = cond("`spec4'" == "toy", "L.y", "L(1/4).newsy L(1/4).y L(1/4).g") . local keep "" . if "`rows4'" == "drop1941q4" local keep "if qdate != tq(1941q4)" . if "`rows4'" == "drop1950q3" local keep "if qdate != tq(1950q3)" . if "`rows4'" == "dropboth" local keep "if qdate != tq(1941q4) & qdate != tq(1950q3)" . if "`rows4'" == "from1947q1" local keep "if qdate >= tq(1947q1)" . . quietly regress F`h4'.y newsy `control' . local bfull = _b[newsy] . local nfull = e(N) . display as text "regress F`h4'.y newsy `control' `keep'" regress F8.y newsy L.y if qdate != tq(1950q3) . regress F`h4'.y newsy `control' `keep' Source | SS df MS Number of obs = 495 -------------+---------------------------------- F(2, 492) = 128.20 Model | 1.37349034 2 .686745172 Prob > F = 0.0000 Residual | 2.6356001 492 .005356911 R-squared = 0.3426 -------------+---------------------------------- Adj R-squared = 0.3399 Total | 4.00909045 494 .008115568 Root MSE = .07319 ------------------------------------------------------------------------------ F8.y | Coefficient Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- newsy | .4339691 .0610969 7.10 0.000 .313926 .5540121 | y | L1. | .5398319 .0364573 14.81 0.000 .4682007 .6114632 | _cons | .4500998 .0361303 12.46 0.000 .379111 .5210886 ------------------------------------------------------------------------------ . local bsel = _b[newsy] . local nsel = e(N) . lp_assert "Handoff Lab 4: `n4' rows, as stored in the browser" : `nsel' == `n4' pass Handoff Lab 4: 495 rows, as stored in the browser . lp_close `bsel' `b4', tol(1e-6) label(Handoff Lab 4: the selected estimate against the browser) Handoff Lab 4: the selected estimate against the browser value 0.43396908 target 0.43396900 |diff| 7.98e-08 tol 1.0e-06 pass Handoff Lab 4: the selected estimate against the browser . lp_assert "Handoff Lab 4: `n4full' rows on the full sample" : `nfull' == `n4full' pass Handoff Lab 4: 496 rows on the full sample . lp_close `bfull' `b4full', tol(1e-6) label(Handoff Lab 4: the full-sample estimate against the browser) Handoff Lab 4: the full-sample estimate against the browser value 0.36190589 target 0.36190600 |diff| 1.14e-07 tol 1.0e-06 pass Handoff Lab 4: the full-sample estimate against the browser . post `T' ("Lab 4") ("estimate at h = `h4', `rows4'") (`b4') (`bsel') (`bsel' - `b4') ("agrees within 1e-6") . post `T' ("Lab 4") ("estimate at h = `h4', full sample") (`b4full') (`bfull') (`bfull' - `b4full') ("agrees within > 1e-6") . . * The hypothesis: direction relative to the full sample, and the number. . local actual = cond(abs(`bsel' - `bfull') < 5e-7, "unchanged", cond(`bsel' > `bfull', "raise", "lower")) . if "`rows4'" == "full" local verdict "no rows were dropped, so there is no direction to test" . else if "`dir4'" == "" local verdict "the hypothesis names no single direction" . else if "`dir4'" == "`actual'" local verdict "direction confirmed" . else local verdict "direction refuted" . display as text _n "Hypothesis direction: " as result cond("`dir4'" == "", "(none found)", "`dir4'") /// > as text ". Stata: the estimate moves from " as result %8.6f `bfull' as text " (`nfull' rows) to " /// > as result %8.6f `bsel' as text " (`nsel' rows), so the rows " as result "`actual'" as text " it." Hypothesis direction: lower. Stata: the estimate moves from 0.361906 (496 rows) to 0.433969 (495 rows), so the rows rai > se it. . display as text "Verdict: `verdict'." Verdict: direction refuted. . local hyp_num = . . if "`num4'" != "" { . local hyp_num = `num4' . display as text "Hypothesized value " as result %8.4f `hyp_num' as text "; estimate " as result %8.6f `bsel' / > // > as text "; miss " as result %8.4f abs(`bsel' - `hyp_num') Hypothesized value 0.3000; estimate 0.433969; miss 0.1340 . } . post `T' ("Lab 4") ("hypothesis: `dir4'") (`hyp_num') (`bsel') (`bsel' - `hyp_num') ("`verdict'") . } . . postclose `T' . use "output/handoff-check.dta", clear . format browser stata difference %12.8f . list, clean noobs lab quantity browser stata difference result Lab 2 slope at h = 2 2.05002400 2.05002437 0.00000037 agrees within 1e-6 Lab 3 slope at h = 0 0.87894000 0.87894028 0.00000028 agrees within 1e-6 Lab 3 slope at h = 1 0.85326000 0.85326038 0.00000038 agrees within 1e-6 Lab 3 slope at h = 2 0.61273700 0.61273705 0.00000005 agrees within 1e-6 Lab 3 slope at h = 3 0.61104600 0.61104632 0.00000032 agrees within 1e-6 Lab 3 slope at h = 4 0.54847700 0.54847739 0.00000039 agrees within 1e-6 Lab 3 slope at h = 5 0.58309900 0.58309851 -0.00000049 agrees within 1e-6 Lab 3 slope at h = 6 0.50912000 0.50912038 0.00000038 agrees within 1e-6 Lab 3 slope at h = 7 0.41778800 0.41778779 -0.00000021 agrees within 1e-6 Lab 3 slope at h = 8 0.24059500 0.24059456 -0.00000044 agrees within 1e-6 Lab 3 slope at h = 9 0.13029300 0.13029288 -0.00000012 agrees within 1e-6 Lab 3 slope at h = 10 -0.02882100 -0.02882139 -0.00000039 agrees within 1e-6 Lab 3 slope at h = 11 -0.11720000 -0.11719967 0.00000033 agrees within 1e-6 Lab 3 slope at h = 12 -0.29329700 -0.29329663 0.00000037 agrees within 1e-6 Lab 4 estimate at h = 8, drop1950q3 0.43396900 0.43396908 0.00000008 agrees within 1e-6 Lab 4 estimate at h = 8, full sample 0.36190600 0.36190589 -0.00000011 agrees within 1e-6 Lab 4 hypothesis: lower 0.30000000 0.43396908 0.13396908 direction refuted . export delimited using "output/handoff-check.csv", replace datafmt (file output/handoff-check.csv not found) file output/handoff-check.csv saved . display as text _n "Handoff check complete." Handoff check complete. . log close handoff name: handoff log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/hando > ff-check.log log type: text closed on: 13 Sep 2026, 22:49:11 ------------------------------------------------------------------------------------------------------------------------ . end of do-file . . timer off 1 . quietly timer list 1 . local seconds = r(t1) . display as text _n "Assertions passed: " as result $LP_NPASS as text "; failed: " as result $LP_NFAIL Assertions passed: 200; failed: 0 . display as text "Runtime: " as result %8.1f `seconds' as text " seconds (R = $R)" Runtime: 137.1 seconds (R = 500) . display as text "Finished `c(current_date)' `c(current_time)'" Finished 13 Sep 2026 22:49:11 . display as result "MASTER COMPLETE" MASTER COMPLETE . log close master name: master log: /Users/tylersotomayor/local-projections-course/practica/p01-question-to-projection/lab-project/output/maste > r.log log type: text closed on: 13 Sep 2026, 22:49:11 ------------------------------------------------------------------------------------------------------------------------