--------------------------------------------------------------------------------------------------------------
      name:  hres
       log:  /Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tie
> nes IMSS/Update26/ThemeH/ThemeH_results.txt
  log type:  text
 opened on:  12 Aug 2026, 19:29:57

. 
. 
. ********************************************************************************
. * SECTION 1: BUILD THE POPULATION-SHARE LONG-DIFFERENCE CELLS
. ********************************************************************************
. * One program builds cells for any (exposed-cohort, control-cohort, year)
. * assignment, so baseline, placebo, and the 2013 pre-period all run through
. * identical code. Outcomes are shares of the cohort-group population:
. * employment, formal employment, informal employment, unemployment,
. * non-participation. Denominator is the full cohort population (clase1 is
. * dropped nowhere here, unlike the conditional-rate cells).
. 
. capture program drop buildcells

. program define buildcells
  1.     syntax , Explo(integer) Exphi(integer) Ctrllo(integer) Ctrlhi(integer) ///
>              Year(integer)
  2. 
.     use "$update23/panel_16_22.dta", clear
  3.     gen year = mod(per,100)+2000
  4.     keep if year==`year'
  5.     keep if inrange(cohort,`ctrllo',`ctrlhi') | inrange(cohort,`explo',`exphi')
  6.     gen exposed = inrange(cohort,`explo',`exphi')
  7. 
.     * NOTE: no "drop if clase1==0" -- population shares need the full population
.     gen byte emp   = (clase2==1)
  8.     gen byte femp  = (formal==1)
  9.     gen byte iemp  = (informal==1)
 10.     gen byte unem  = (clase1==1 & clase2==2)
 11.     gen byte nopart= (clase1!=1)
 12. 
.     egen pop    = total(fac),           by(per exposed state)
 13.     egen n_emp  = total(fac*emp),       by(per exposed state)
 14.     egen n_form = total(fac*femp),      by(per exposed state)
 15.     egen n_inf  = total(fac*iemp),      by(per exposed state)
 16.     egen n_un   = total(fac*unem),      by(per exposed state)
 17.     egen n_np   = total(fac*nopart),    by(per exposed state)
 18. 
.     gen s_emp  = 100*n_emp/pop
 19.     gen s_form = 100*n_form/pop
 20.     gen s_inf  = 100*n_inf/pop
 21.     gen s_un   = 100*n_un/pop
 22.     gen s_np   = 100*n_np/pop
 23. 
.     collapse s_emp s_form s_inf s_un s_np (sum) fac, by(per exposed state)
 24. 
.     * wide: exposed-minus-unexposed gap per state-quarter
.     reshape wide s_emp s_form s_inf s_un s_np fac, i(per state) j(exposed)
 25.     foreach v in emp form inf un np {
 26.         gen d_`v' = s_`v'1 - s_`v'0
 27.     }
 28.     gen fac = fac1 + fac0
 29.     gen w   = sqrt(fac1)               // exposed-cohort cell population, as in
 30.                                        // the main long differences
. 
.     sort state
 31.     merge m:1 state using "$update23/longdiff_covariates"
 32.         keep if _merge==3
 33.         drop _merge
 34.     replace gdp_pc = ln(gdp_pc)
 35.     mkregion
 36. 
.     gen quarter = int(per/100)
 37.     gen t = per
 38. end

. 
. 
. ********************************************************************************
. * SECTION 1.1: VALIDATE -- reproduce Table A.2 Panel B
. ********************************************************************************
. di as res _n(2) "{hline 78}"


------------------------------------------------------------------------------

. di as res "SECTION 1.1: baseline (must reproduce Table A.2 Panel B:"
SECTION 1.1: baseline (must reproduce Table A.2 Panel B:

. di as res "  employment 0.61, formal 0.90, informal -0.29, unemp -0.02,"
  employment 0.61, formal 0.90, informal -0.29, unemp -0.02,

. di as res "  nonpart -0.59; adding-up: formal+informal=employment,"
  nonpart -0.59; adding-up: formal+informal=employment,

. di as res "  emp+unemp+nonpart coefficients sum to zero with participation)"
  emp+unemp+nonpart coefficients sum to zero with participation)

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. buildcells, explo(2001) exphi(2004) ctrllo(1995) ctrlhi(1998) year(2019)
(2,093,103 observations deleted)
(155,939 observations deleted)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations              256   ->   128         
Number of variables                   9   ->   14          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
                                   s_un   ->   s_un0 s_un1
                                   s_np   ->   s_np0 s_np1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               128  (_merge==3)
    -----------------------------------------
(0 observations deleted)
(128 real changes made)
(128 missing values generated)
(24 real changes made)
(12 real changes made)
(16 real changes made)
(16 real changes made)
(20 real changes made)
(12 real changes made)
(12 real changes made)
(16 real changes made)

. 
. foreach v in emp form inf un np {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t [aw=w], ///
>         cluster(state)
  3.     hpost inf_pre, block("baseline") outcome("`v'")
  4. }
    emp               0.624  (  0.082)   WCB p =  0.000   N = 128
    form              0.903  (  0.090)   WCB p =  0.000   N = 128
    inf              -0.279  (  0.079)   WCB p =  0.015   N = 128
    un               -0.035  (  0.040)   WCB p =  0.521   N = 128
    np               -0.589  (  0.089)   WCB p =  0.000   N = 128

. 
. di as txt _n "  Adding-up (coefficients): form + inf should equal emp"

  Adding-up (coefficients): form + inf should equal emp

. 
. 
. ********************************************************************************
. * SECTION 2: THE MATCHED PLACEBO  <- THE DECISION TEST
. ********************************************************************************
. * Table 4 Panel A design exactly: placebo exposed 1995-1998, controls 1991-1994,
. * long differences in 2019, full controls. Outcomes are population shares.
. * Age structure: 21-24 vs 25-28 in 2019 -- the same 4-year cohort spacing as
. * the baseline design (15-18 vs 21-24 differ in spacing; the placebo matches
. * Table 4, which is the paper's own falsification standard).
. 
. di as res _n(2) "{hline 78}"


------------------------------------------------------------------------------

. di as res "SECTION 2: matched placebo (Table 4 Panel A design, population"
SECTION 2: matched placebo (Table 4 Panel A design, population

. di as res "  shares). DECISION TEST: promote only if s_form placebo has"
  shares). DECISION TEST: promote only if s_form placebo has

. di as res "  WCB p > 0.10 and |coef| < 0.22."
  WCB p > 0.10 and |coef| < 0.22.

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. buildcells, explo(1995) exphi(1998) ctrllo(1991) ctrlhi(1994) year(2019)
(2,093,103 observations deleted)
(173,472 observations deleted)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations              256   ->   128         
Number of variables                   9   ->   14          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
                                   s_un   ->   s_un0 s_un1
                                   s_np   ->   s_np0 s_np1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               128  (_merge==3)
    -----------------------------------------
(0 observations deleted)
(128 real changes made)
(128 missing values generated)
(24 real changes made)
(12 real changes made)
(16 real changes made)
(16 real changes made)
(20 real changes made)
(12 real changes made)
(12 real changes made)
(16 real changes made)

. 
. foreach v in emp form inf un np {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t [aw=w], ///
>         cluster(state)
  3.     hpost inf_pre, block("placebo_ld") outcome("`v'")
  4. }
    emp              -0.100  (  0.077)   WCB p =  0.236   N = 128
    form             -0.057  (  0.099)   WCB p =  0.603   N = 128
    inf              -0.043  (  0.075)   WCB p =  0.587   N = 128
    un               -0.007  (  0.027)   WCB p =  0.842   N = 128
    np                0.107  (  0.070)   WCB p =  0.174   N = 128

. 
. * Also without controls (Table 4 shows Panel A with controls; Table 2 shows the
. * raw gradient matters -- report both so a referee cannot pick the worse one)
. foreach v in form inf {
  2.     quietly reg d_`v' inf_pre i.t [aw=w], cluster(state)
  3.     hpost inf_pre, block("placebo_nc") outcome("`v'")
  4. }
    form              0.122  (  0.052)   WCB p =  0.047   N = 128
    inf              -0.049  (  0.031)   WCB p =  0.137   N = 128

. 
. 
. ********************************************************************************
. * SECTION 3: A.6 ANALOGUE -- CONDITION ON PRE-EXISTING 2013 GAPS
. ********************************************************************************
. * Table A.6 cut conditional formality from 0.87 to 0.58 by conditioning on the
. * 2013 cross-cohort gap. The population-share version: build the same gap in
. * 2013 for ages 15-18 vs 21-24 by state-quarter, merge onto the 2019 cells by
. * state and calendar quarter, and condition. If formal-employment survives, the
. * decomposition is not merely persistent state-level age structure.
. 
. di as res _n(2) "{hline 78}"


------------------------------------------------------------------------------

. di as res "SECTION 3: conditioning on 2013 population-share cohort gaps"
SECTION 3: conditioning on 2013 population-share cohort gaps

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. * 3.1 the 2013 pre-period gaps, from the raw ENOE 2013 files
. tempfile lags13

. local first = 1

. forvalues q = 1/4 {
  2.     use "$enoe/sdemt`q'13.dta", clear
  3.     capture confirm variable state
  4.     if _rc rename ent state          // raw SDEM names it ent
  5. 
.     gen valid=(r_def==0 & (c_res==1 | c_res==3) & inrange(eda,15,98))
  6.     keep if valid==1
  7.     keep if inrange(eda,15,18) | inrange(eda,21,24)
  8.     gen exposed = inrange(eda,15,18)
  9. 
.     gen informal=0 if clase2==1
 10.         replace informal=1 if tue2==5
 11.         replace informal=1 if pos_ocu==3 & rama==6
 12.         replace informal=1 if pos_ocu==4
 13.         replace informal=1 if inrange(seg_soc,2,3) & tue2==6
 14.         replace informal=1 if pos_ocu==1 & remune2c==1 & (tue2!=5 | tue2!=6 | tue2!=7) & inrange(seg_soc,
> 2,3)
 15.         replace informal=1 if pos_ocu==1 & remune2c==2 & (tue2!=5 | tue2!=6 | tue2!=7) & inrange(seg_soc,
> 2,3)
 16.         replace informal=1 if pos_ocu==5 & inrange(seg_soc,2,3)
 17.     gen formal = 1-informal
 18. 
.     gen byte emp  = (clase2==1)
 19.     gen byte femp = (formal==1)
 20.     gen byte iemp = (informal==1)
 21. 
.     egen pop    = total(fac),      by(exposed state)
 22.     egen n_emp  = total(fac*emp),  by(exposed state)
 23.     egen n_form = total(fac*femp), by(exposed state)
 24.     egen n_inf  = total(fac*iemp), by(exposed state)
 25. 
.     gen s_emp  = 100*n_emp/pop
 26.     gen s_form = 100*n_form/pop
 27.     gen s_inf  = 100*n_inf/pop
 28. 
.     collapse s_emp s_form s_inf, by(exposed state)
 29.     reshape wide s_emp s_form s_inf, i(state) j(exposed)
 30.     foreach v in emp form inf {
 31.         gen lag_`v' = s_`v'1 - s_`v'0
 32.     }
 33.     gen quarter = `q'
 34.     keep state quarter lag_*
 35. 
.     if `first' {
 36.         save "`lags13'"
 37.         local first = 0
 38.     }
 39.     else {
 40.         append using "`lags13'"
 41.         save "`lags13'", replace
 42.     }
 43. }
(109,760 observations deleted)
(225,719 observations deleted)
(34,643 missing values generated)
(5,953 real changes made)
(204 real changes made)
(1,683 real changes made)
(756 real changes made)
(5,865 real changes made)
(623 real changes made)
(0 real changes made)
(34,643 missing values generated)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations               64   ->   32          
Number of variables                   5   ->   7           
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
-----------------------------------------------------------------------------
file /var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//S_22909.000002 saved as .dta format
(110,336 observations deleted)
(225,690 observations deleted)
(33,674 missing values generated)
(6,035 real changes made)
(209 real changes made)
(1,878 real changes made)
(779 real changes made)
(5,906 real changes made)
(646 real changes made)
(0 real changes made)
(33,674 missing values generated)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations               64   ->   32          
Number of variables                   5   ->   7           
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
-----------------------------------------------------------------------------
(label ent already defined)
file /var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//S_22909.000002 saved as .dta format
(111,464 observations deleted)
(226,028 observations deleted)
(33,683 missing values generated)
(5,887 real changes made)
(219 real changes made)
(1,914 real changes made)
(785 real changes made)
(6,020 real changes made)
(581 real changes made)
(0 real changes made)
(33,683 missing values generated)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations               64   ->   32          
Number of variables                   5   ->   7           
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
-----------------------------------------------------------------------------
(label ent already defined)
file /var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//S_22909.000002 saved as .dta format
(113,327 observations deleted)
(229,327 observations deleted)
(33,776 missing values generated)
(6,059 real changes made)
(183 real changes made)
(1,980 real changes made)
(799 real changes made)
(6,196 real changes made)
(587 real changes made)
(0 real changes made)
(33,776 missing values generated)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations               64   ->   32          
Number of variables                   5   ->   7           
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
-----------------------------------------------------------------------------
(label ent already defined)
file /var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//S_22909.000002 saved as .dta format

. 
. * 3.2 2019 cells, merged with the lagged gaps by state and calendar quarter
. buildcells, explo(2001) exphi(2004) ctrllo(1995) ctrlhi(1998) year(2019)
(2,093,103 observations deleted)
(155,939 observations deleted)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations              256   ->   128         
Number of variables                   9   ->   14          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
                                   s_un   ->   s_un0 s_un1
                                   s_np   ->   s_np0 s_np1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               128  (_merge==3)
    -----------------------------------------
(0 observations deleted)
(128 real changes made)
(128 missing values generated)
(24 real changes made)
(12 real changes made)
(16 real changes made)
(16 real changes made)
(20 real changes made)
(12 real changes made)
(12 real changes made)
(16 real changes made)

. merge m:1 state quarter using "`lags13'"
(label ent already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               128  (_merge==3)
    -----------------------------------------

.     keep if _merge==3
(0 observations deleted)

.     drop _merge

. 
. foreach v in emp form inf {
  2.     quietly reg d_`v' inf_pre lag_`v' gdp_pc school_attain i.region i.t ///
>         [aw=w], cluster(state)
  3.     hpost inf_pre, block("cond2013") outcome("`v'")
  4.     di as txt "      coefficient on lagged gap: " %7.3f _b[lag_`v'] ///
>         "  (" %6.3f _se[lag_`v'] ")"
  5. }
    emp               0.616  (  0.090)   WCB p =  0.000   N = 128
      coefficient on lagged gap:   0.014  ( 0.114)
    form              0.552  (  0.186)   WCB p =  0.009   N = 128
      coefficient on lagged gap:   0.457  ( 0.197)
    inf              -0.260  (  0.090)   WCB p =  0.028   N = 128
      coefficient on lagged gap:   0.092  ( 0.112)

. 
. 
. ********************************************************************************
. * SECTION 4: PANEL VERSION WITH INFORMALITY-SPECIFIC COHORT TRENDS
. ********************************************************************************
. * The A.5 analogue for the decomposition: panel 2016-2019, cohorts 1991-2004,
. * population shares, adding informality x linear cohort trend. If formal
. * employment holds up as conditional formality does in A.5 (1.28 -> 1.09), the
. * decomposition inherits A.5's robustness. Sharper than re-running all of A.5;
. * one column suffices for the promotion decision.
. 
. di as res _n(2) "{hline 78}"


------------------------------------------------------------------------------

. di as res "SECTION 4: panel population shares, with and without informality x"
SECTION 4: panel population shares, with and without informality x

. di as res "  cohort trend (A.5 col 3 analogue)"
  cohort trend (A.5 col 3 analogue)

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. use "$update23/panel_16_22.dta", clear

. gen year = mod(per,100)+2000

. keep if inrange(year,2016,2019)
(952,017 observations deleted)

. keep if inrange(cohort,1991,2004)
(0 observations deleted)

. 
. gen byte emp  = (clase2==1)

. gen byte femp = (formal==1)

. gen byte iemp = (informal==1)

. 
. egen pop    = total(fac),      by(per cohort state)

. egen n_emp  = total(fac*emp),  by(per cohort state)

. egen n_form = total(fac*femp), by(per cohort state)

. egen n_inf  = total(fac*iemp), by(per cohort state)

. 
. gen s_emp  = 100*n_emp/pop

. gen s_form = 100*n_form/pop

. gen s_inf  = 100*n_inf/pop

. 
. collapse s_emp s_form s_inf (sum) fac, by(per cohort state)

. sort state

. merge m:1 state using "$update23/longdiff_covariates"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                             7,168  (_merge==3)
    -----------------------------------------

.     keep if _merge==3
(0 observations deleted)

.     drop _merge

. replace gdp_pc = ln(gdp_pc)
(7,168 real changes made)

. gen t = per

. gen w = sqrt(fac)

. 
. gen exposure = inrange(cohort,2001,2004)

.     replace exposure = 1/3 if cohort==1999
(512 real changes made)

.     replace exposure = 2/3 if cohort==2000
(512 real changes made)

. gen exp_inf    = exposure*inf_pre

. gen gdp_exp    = gdp_pc*exposure

. gen school_exp = school_attain*exposure

. gen ctrend     = cohort-1991

. gen inf_ctrend = inf_pre*ctrend

. 
. foreach v in emp form inf {
  2.     quietly areg s_`v' exp_inf gdp_exp school_exp i.state i.t [aw=w], ///
>         absorb(cohort) cluster(state)
  3.     hpost exp_inf, block("panel_base") outcome("`v'")
  4. }
    emp               0.434  (  0.040)   WCB p =  0.000   N = 7168
    form              0.960  (  0.051)   WCB p =  0.000   N = 7168
    inf              -0.526  (  0.038)   WCB p =  0.000   N = 7168

. foreach v in emp form inf {
  2.     quietly areg s_`v' exp_inf inf_ctrend gdp_exp school_exp i.state i.t ///
>         [aw=w], absorb(cohort) cluster(state)
  3.     hpost exp_inf, block("panel_trend") outcome("`v'")
  4. }
    emp               0.157  (  0.065)   WCB p =  0.033   N = 7168
    form              0.468  (  0.054)   WCB p =  0.000   N = 7168
    inf              -0.311  (  0.052)   WCB p =  0.000   N = 7168

. 
. 
. ********************************************************************************
. * SECTION 5: INFERENCE AND LEVERAGE ON THE DECOMPOSITION
. ********************************************************************************
. 
. di as res _n(2) "{hline 78}"


------------------------------------------------------------------------------

. di as res "SECTION 5: CV3 and leave-one-state-out for the baseline decomposition"
SECTION 5: CV3 and leave-one-state-out for the baseline decomposition

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. buildcells, explo(2001) exphi(2004) ctrllo(1995) ctrlhi(1998) year(2019)
(2,093,103 observations deleted)
(155,939 observations deleted)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations              256   ->   128         
Number of variables                   9   ->   14          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                  s_emp   ->   s_emp0 s_emp1
                                 s_form   ->   s_form0 s_form1
                                  s_inf   ->   s_inf0 s_inf1
                                   s_un   ->   s_un0 s_un1
                                   s_np   ->   s_np0 s_np1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               128  (_merge==3)
    -----------------------------------------
(0 observations deleted)
(128 real changes made)
(128 missing values generated)
(24 real changes made)
(12 real changes made)
(16 real changes made)
(16 real changes made)
(20 real changes made)
(12 real changes made)
(12 real changes made)
(16 real changes made)

. 
. * 5.1 CV3 (jackknife) standard errors, by hand (vce(jackknife) rejects aweights)
. foreach v in form inf {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t [aw=w], ///
>         cluster(state)
  3.     local bC = _b[inf_pre]
  4.     local s1 = _se[inf_pre]
  5. 
.     quietly levelsof state, local(states)
  6.     local G : word count `states'
  7.     tempname BJ
  8.     matrix `BJ' = J(`G',1,.)
  9.     local g = 0
 10.     foreach s of local states {
 11.         local ++g
 12.         quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>             if state!=`s' [aw=w], cluster(state)
 13.         matrix `BJ'[`g',1] = _b[inf_pre]
 14.     }
 15.     mata: bj = st_matrix(st_local("BJ")); ///
>           st_local("cv3", strofreal(sqrt((rows(bj)-1)/rows(bj) * ///
>           sum((bj:-mean(bj)):^2))))
 16.     di as txt "  `v':  b = " %6.3f `bC' "   CRV1 se " %6.3f `s1' ///
>         "   CV3 se " %6.3f `cv3' "   ratio " %4.2f `cv3'/`s1'
 17. }
  form:  b =  0.903   CRV1 se  0.090   CV3 se  0.134   ratio 1.48
  inf:  b = -0.279   CRV1 se  0.079   CV3 se  0.112   ratio 1.41

. 
. * 5.2 leave-one-state-out range
. foreach v in form inf {
  2.     local bmin =  1e9
  3.     local bmax = -1e9
  4.     quietly levelsof state, local(states)
  5.     foreach s of local states {
  6.         quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>             if state!=`s' [aw=w], cluster(state)
  7.         if _b[inf_pre] < `bmin' local bmin = _b[inf_pre]
  8.         if _b[inf_pre] > `bmax' local bmax = _b[inf_pre]
  9.     }
 10.     di as txt "  `v':  leave-one-out range [" %6.3f `bmin' ", " %6.3f `bmax' "]"
 11. }
  form:  leave-one-out range [ 0.857,  0.975]
  inf:  leave-one-out range [-0.334, -0.243]

. 
. * 5.3 excluding Chiapas, Guerrero, Oaxaca (7 12 20), as in Table A.3
. foreach v in form inf {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>         if !inlist(state,7,12,20) [aw=w], cluster(state)
  3.     hpost inf_pre, block("no_south") outcome("`v'")
  4. }
    form              0.915  (  0.094)   WCB p =  0.000   N = 116
    inf              -0.257  (  0.077)   WCB p =  0.020   N = 116

. 
. *=====  Theme H addendum: Panel C (wage vs self-employment split)  =====*
. * Shares of cohort-group population, same 128 cells as the baseline block:
. *   formal_wage   : formal   & pos_ocu==1  (subordinados y remunerados)
. *   formal_self   : formal   & pos_ocu!=1  (empleadores, cuenta propia, sin pago)
. *   informal_wage : informal & pos_ocu==1
. *   informal_self : informal & pos_ocu!=1
. 
. set seed 2026

. foreach y in formal_wage formal_self informal_wage informal_self {
  2.     quietly reg gap_`y' c.I_pre i.q $Xcontrols [aw=w_sqrtpop], vce(cluster ent)
  3.     scalar b_`y' = _b[I_pre]
  4.     boottest I_pre, weighttype(webb) reps(9999) nograph
  5.     * post to resfile: block="split", outcome="`y'", b, se, pwcb=r(p), ci, n
. }
w_sqrtpop not found
r(111);

end of do-file

r(111);

. log close
no log file open
r(606);

. clear

. use "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IM
> SS/Update23/longdiff.dta"

. do "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IMS
> S/Update26/ThemeH/ThemeH_panelC_split.do"

. *==============================================================================
. * Tienes IMSS -- Table 3, Panel C
. * Formal / informal employment split into wage vs. self-employment & other
. *
. * Adapted to the Update23 build conventions:
. *   - starts from panel_16_22.dta
. *   - state (not ent), w = sqrt(fac), inf_pre, gdp_pc, school_attain, i.region, i.t
. *   - informal defined exactly as in the Update23 microdata block
. *
. * SELF-CONTAINED BY DESIGN. Section 2 reproduces the Panel A aggregates first.
. * If they match ThemeH_summary (0.624 / 0.903 / -0.279 / -0.035 / -0.589), the
. * cell build is identical to the one behind Table 3 and Panel C is consistent.
. * If they do not match, fix the switches in Section 0 before using any output.
. *==============================================================================
. 
. version 17

. clear all
file /var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//S_22909.000001 not found

. set more off

. 
. *------------------------------------------------------------------------------
. * 0. PATHS AND SWITCHES
. *------------------------------------------------------------------------------
. global work  "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/
> Tienes IMSS/Update26"

. global build "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/
> Tienes IMSS/Update23"

. * ^ wherever panel_16_22.dta and longdiff_covariates.dta actually live
. 
. cd "$work"
/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IMSS/Upda
> te26

. 
. * Weight convention. Update23 collapses by(per state), so fac is summed across
. * BOTH cohort groups -> WTOTAL = 1. Flip to 0 only if 1 fails validation.
. local WTOTAL 1

. 
. * Theme H baseline targets (2026-08-11 log)
. local T_emp   =  0.624

. local T_form  =  0.903

. local T_inf   = -0.279

. local T_unem  = -0.035

. local T_nonp  = -0.589

. 
. capture which boottest

. if _rc {
.     di as error "boottest not installed: ssc install boottest"
.     exit 199
. }

. 
. *------------------------------------------------------------------------------
. * 1. BUILD: population shares at the cohort-group x state x quarter level
. *------------------------------------------------------------------------------
. use "$build/panel_16_22.dta", clear

. 
. * Long-difference cohort groups (same as Update23 LD block)
. drop if inrange(cohort,1999,2000) | cohort < 1995
(1,033,327 observations deleted)

. gen byte exposed = inrange(cohort,2001,2004)

. 
. drop if clase1 == 0            /* keep PEA and PNEA only, as in Update23 */
(13,382 observations deleted)

. 
. * --- labor-market status indicators, defined over the WHOLE cohort population.
. * Denominator is everyone in the cell, so these are 0 (not missing) for people
. * outside the category. Note `informal' is missing for the non-employed, which
. * is why each indicator is anchored on clase2/clase1 first.
. gen byte emp  = (clase2 == 1)

. gen byte unem = (clase2 == 2)

. gen byte nonp = (clase1 == 2)

. gen byte form = (clase2 == 1 & informal == 0)

. gen byte inf  = (clase2 == 1 & informal == 1)

. 
. * --- wage vs. self-employment & other (Panel C) ------------------------------
. * pos_ocu: 1 = subordinados y remunerados; 2 = empleadores; 3 = cuenta propia;
. *          4 = sin pago; 5 = no especificado.
. * wage_job is 0 for missing pos_ocu, so the "& other" column absorbs any
. * unspecified-position employed and the split adds up EXACTLY by construction.
. gen byte wage_job = (pos_ocu == 1)

. 
. gen byte fwage = (form == 1 &  wage_job)

. gen byte fself = (form == 1 & !wage_job)

. gen byte iwage = (inf  == 1 &  wage_job)

. gen byte iself = (inf  == 1 & !wage_job)

. 
. * transparency: how many employed carry an unspecified position
. quietly count if clase2 == 1 & missing(pos_ocu)

. di as txt "Employed with missing pos_ocu: " as res r(N)
Employed with missing pos_ocu: 0

. 
. * individual-level identities
. assert emp  == form  + inf

. assert form == fwage + fself

. assert inf  == iwage + iself

. 
. *--- collapse to cells --------------------------------------------------------
. collapse (mean) emp form inf unem nonp fwage fself iwage iself ///
>          (rawsum) fac [pw=fac], by(per state exposed)

. 
. foreach v of varlist emp form inf unem nonp fwage fself iwage iself {
  2.     replace `v' = 100 * `v'
  3. }
(1,728 real changes made)
(1,546 real changes made)
(1,728 real changes made)
(1,684 real changes made)
(1,728 real changes made)
(1,535 real changes made)
(1,099 real changes made)
(1,728 real changes made)
(1,728 real changes made)

. 
. reshape wide emp form inf unem nonp fwage fself iwage iself fac, ///
>     i(per state) j(exposed)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations            1,728   ->   864         
Number of variables                  13   ->   22          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                    emp   ->   emp0 emp1
                                   form   ->   form0 form1
                                    inf   ->   inf0 inf1
                                   unem   ->   unem0 unem1
                                   nonp   ->   nonp0 nonp1
                                  fwage   ->   fwage0 fwage1
                                  fself   ->   fself0 fself1
                                  iwage   ->   iwage0 iwage1
                                  iself   ->   iself0 iself1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

. 
. *--- exposed-minus-unexposed gaps --------------------------------------------
. foreach v in emp form inf unem nonp fwage fself iwage iself {
  2.     gen double d_`v' = `v'1 - `v'0
  3. }

. 
. *--- weights, time, covariates (Update23 conventions) ------------------------
. gen double fac_tot = fac0 + fac1

. if `WTOTAL' {
.     gen double w = sqrt(fac_tot)
. }

. else {
.     gen double w = sqrt(fac1)
. }

. 
. gen year    = mod(per,100) + 2000

. gen quarter = int(per/100)

. gen t       = yq(year, quarter)

. 
. sort state

. merge m:1 state using "$build/longdiff_covariates.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               864  (_merge==3)
    -----------------------------------------

.     drop _merge

.     replace gdp_pc = ln(gdp_pc)
(864 real changes made)

.     gen region = .
(864 missing values generated)

.     replace region = 1 if inlist(state,2,3,8,10,25,26)      /*Noroeste*/
(162 real changes made)

.     replace region = 2 if inlist(state,5,19,28)             /*Noreste*/
(81 real changes made)

.     replace region = 3 if inlist(state,6,14,16,18)          /*Occidente*/
(108 real changes made)

.     replace region = 4 if inlist(state,13,21,29,30)         /*Oriente*/
(108 real changes made)

.     replace region = 5 if inlist(state,1,11,22,24,32)       /*Centronorte*/
(135 real changes made)

.     replace region = 6 if inlist(state,9,15,17)             /*Centrosur*/
(81 real changes made)

.     replace region = 7 if inlist(state,7,12,20)             /*Suroeste*/
(81 real changes made)

.     replace region = 8 if inlist(state,4,23,27,31)          /*Sureste*/
(108 real changes made)

. 
. save "ThemeH/ld_shares_2019.dta", replace
(file ThemeH/ld_shares_2019.dta not found)
file ThemeH/ld_shares_2019.dta saved

. 
. *------------------------------------------------------------------------------
. * 2. VALIDATION: reproduce Panel A before trusting Panel C
. *------------------------------------------------------------------------------
. local SPEC "inf_pre gdp_pc school_attain i.region i.t"

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "VALIDATION vs ThemeH baseline"
VALIDATION vs ThemeH baseline

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  outcome        this build      Theme H     diff"
  outcome        this build      Theme H     diff

. 
. local ok = 1

. foreach v in emp form inf unem nonp {
  2.     quietly reg d_`v' `SPEC' [aw=w] if year == 2019, cluster(state)
  3.     scalar got_`v' = _b[inf_pre]
  4.     local  d = got_`v' - `T_`v''
  5.     di as txt "  " %-12s "`v'" as res %10.3f got_`v' ///
>        as res %12.3f `T_`v'' as res %9.3f `d'
  6.     if abs(`d') > 0.005 local ok = 0
  7. }
  emp              0.627       0.624    0.003
  form             0.904       0.903    0.001
  inf             -0.277      -0.279    0.002
  unem            -0.035      -0.035    0.000
  nonp            -0.592      -0.589   -0.003

. 
. if !`ok' {
.     di as error _n "  MISMATCH. Do not use Panel C output yet."
.     di as error "  Try: flip WTOTAL to 0; or check whether the Update26 build"
.     di as error "  restricts the sample or defines the cells differently."
.     exit 9
. }

. di as res _n "  -> PASS. Cell build matches the Table 3 specification."

  -> PASS. Cell build matches the Table 3 specification.

. 
. *------------------------------------------------------------------------------
. * 3. PANEL C: estimation with wild cluster bootstrap
. *------------------------------------------------------------------------------
. tempname pf

. postfile `pf' str12 block str8 outcome double(b se pwcb lo hi) int n ///
>     using "ThemeH/ThemeH_results_split.dta", replace
(file ThemeH/ThemeH_results_split.dta not found)

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "PANEL C ESTIMATES"
PANEL C ESTIMATES

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. foreach v in fwage fself iwage iself {
  2. 
.     quietly reg d_`v' `SPEC' [aw=w] if year == 2019, cluster(state)
  3.     scalar b_`v'  = _b[inf_pre]
  4.     scalar se_`v' = _se[inf_pre]
  5.     local  n_`v'  = e(N)
  6. 
.     boottest inf_pre, weighttype(webb) reps(9999) seed(2026) nograph
  7.     scalar p_`v' = r(p)
  8.     matrix CI    = r(CI)
  9. 
.     post `pf' ("split") ("`v'") (b_`v') (se_`v') (p_`v') ///
>               (CI[1,1]) (CI[1,2]) (`n_`v'')
 10. 
.     di as txt "  " %-7s "`v'" as res %8.3f b_`v' ///
>        as txt "  (" as res %5.3f se_`v' as txt ")  WCB p = " as res %5.3f p_`v'
 11. }

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     9.3947
                        Prob>|t| =     0.0000

95% confidence set for null hypothesis expression: [.6531, 1.154]
  fwage     0.890  (0.095)  WCB p = 0.000

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     1.4192
                        Prob>|t| =     0.2421

95% confidence set for null hypothesis expression: [−.01116, .03706]
  fself     0.014  (0.010)  WCB p = 0.242

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =    -4.0920
                        Prob>|t| =     0.0112

95% confidence set for null hypothesis expression: [−.4301, −.09517]
  iwage    -0.281  (0.069)  WCB p = 0.011

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     0.0739
                        Prob>|t| =     0.9572

95% confidence set for null hypothesis expression: [−.1374, .1442]
  iself     0.004  (0.053)  WCB p = 0.957

. postclose `pf'

. 
. *------------------------------------------------------------------------------
. * 4. ADDING-UP AUDIT
. *------------------------------------------------------------------------------
. scalar sum_f = b_fwage + b_fself

. scalar sum_i = b_iwage + b_iself

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "ADDING-UP AUDIT"
ADDING-UP AUDIT

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  formal:    wage + self = " as res %7.3f sum_f ///
>    as txt "   Panel A = " as res %7.3f got_form
  formal:    wage + self =   0.904   Panel A =   0.904

. di as txt "  informal:  wage + self = " as res %7.3f sum_i ///
>    as txt "   Panel A = " as res %7.3f got_inf
  informal:  wage + self =  -0.277   Panel A =  -0.277

. 
. assert abs(sum_f - got_form) < 0.002

. assert abs(sum_i - got_inf)  < 0.002

. di as res _n "  -> PASS."

  -> PASS.

. 
. *------------------------------------------------------------------------------
. * 5. VALUES FOR THE LaTeX TABLE
. *------------------------------------------------------------------------------
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "PASTE INTO TABLE 3, PANEL C"
PASTE INTO TABLE 3, PANEL C

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  order: formal wage | formal self&other | informal wage | informal self&other"
  order: formal wage | formal self&other | informal wage | informal self&other

. foreach v in fwage fself iwage iself {
  2.     local st ""
  3.     if p_`v' < 0.10 local st "*"
  4.     if p_`v' < 0.05 local st "**"
  5.     if p_`v' < 0.01 local st "***"
  6.     di as txt "  " %-7s "`v'" as res %5.2f b_`v' "`st'" ///
>        as txt "  (" as res %4.2f se_`v' as txt ")  [" as res %5.3f p_`v' as txt "]"
  7. }
  fwage   0.89***  (0.09)  [0.000]
  fself   0.01  (0.01)  [0.242]
  iwage  -0.28**  (0.07)  [0.011]
  iself   0.00  (0.05)  [0.957]

. 
. *==============================================================================
. * END
. *==============================================================================
. 
end of do-file

. do "/var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//SD22909.000000"

. *==============================================================================
. * Tienes IMSS -- Table 3, Panel C
. * Formal / informal employment split into wage vs. self-employment & other
. *
. * Adapted to the Update23 build conventions:
. *   - starts from panel_16_22.dta
. *   - state (not ent), w = sqrt(fac), inf_pre, gdp_pc, school_attain, i.region, i.t
. *   - informal defined exactly as in the Update23 microdata block
. *
. * SELF-CONTAINED BY DESIGN. Section 2 reproduces the Panel A aggregates first.
. * If they match ThemeH_summary (0.624 / 0.903 / -0.279 / -0.035 / -0.589), the
. * cell build is identical to the one behind Table 3 and Panel C is consistent.
. * If they do not match, fix the switches in Section 0 before using any output.
. *==============================================================================
. 
. version 17

. clear all

. set more off

. 
. *------------------------------------------------------------------------------
. * 0. PATHS AND SWITCHES
. *------------------------------------------------------------------------------
. global work  "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/
> Tienes IMSS/Update26"

. global build "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/
> Tienes IMSS/Update23"

. * ^ wherever panel_16_22.dta and longdiff_covariates.dta actually live
. 
. cd "$work"
/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IMSS/Upda
> te26

. 
. * Weight convention. Update23 collapses by(per state), so fac is summed across
. * BOTH cohort groups -> WTOTAL = 1. Flip to 0 only if 1 fails validation.
. local WTOTAL 1

. 
. * Theme H baseline targets (2026-08-11 log)
. local T_emp   =  0.624

. local T_form  =  0.903

. local T_inf   = -0.279

. local T_unem  = -0.035

. local T_nonp  = -0.589

. 
. capture which boottest

. if _rc {
.     di as error "boottest not installed: ssc install boottest"
.     exit 199
. }

. 
. *------------------------------------------------------------------------------
. * 1. BUILD: population shares at the cohort-group x state x quarter level
. *------------------------------------------------------------------------------
. use "$build/panel_16_22.dta", clear

. 
. * Long-difference cohort groups (same as Update23 LD block)
. drop if inrange(cohort,1999,2000) | cohort < 1995
(1,033,327 observations deleted)

. gen byte exposed = inrange(cohort,2001,2004)

. 
. drop if clase1 == 0            /* keep PEA and PNEA only, as in Update23 */
(13,382 observations deleted)

. 
. * --- labor-market status indicators, defined over the WHOLE cohort population.
. * Denominator is everyone in the cell, so these are 0 (not missing) for people
. * outside the category. Note `informal' is missing for the non-employed, which
. * is why each indicator is anchored on clase2/clase1 first.
. gen byte emp  = (clase2 == 1)

. gen byte unem = (clase2 == 2)

. gen byte nonp = (clase1 == 2)

. gen byte form = (clase2 == 1 & informal == 0)

. gen byte inf  = (clase2 == 1 & informal == 1)

. 
. * --- wage vs. self-employment & other (Panel C) ------------------------------
. * pos_ocu: 1 = subordinados y remunerados; 2 = empleadores; 3 = cuenta propia;
. *          4 = sin pago; 5 = no especificado.
. * wage_job is 0 for missing pos_ocu, so the "& other" column absorbs any
. * unspecified-position employed and the split adds up EXACTLY by construction.
. gen byte wage_job = (pos_ocu == 1)

. 
. gen byte fwage = (form == 1 &  wage_job)

. gen byte fself = (form == 1 & !wage_job)

. gen byte iwage = (inf  == 1 &  wage_job)

. gen byte iself = (inf  == 1 & !wage_job)

. 
. * transparency: how many employed carry an unspecified position
. quietly count if clase2 == 1 & missing(pos_ocu)

. di as txt "Employed with missing pos_ocu: " as res r(N)
Employed with missing pos_ocu: 0

. 
. * individual-level identities
. assert emp  == form  + inf

. assert form == fwage + fself

. assert inf  == iwage + iself

. 
. *--- collapse to cells --------------------------------------------------------
. collapse (mean) emp form inf unem nonp fwage fself iwage iself ///
>          (rawsum) fac [pw=fac], by(per state exposed)

. 
. foreach v of varlist emp form inf unem nonp fwage fself iwage iself {
  2.     replace `v' = 100 * `v'
  3. }
(1,728 real changes made)
(1,546 real changes made)
(1,728 real changes made)
(1,684 real changes made)
(1,728 real changes made)
(1,535 real changes made)
(1,099 real changes made)
(1,728 real changes made)
(1,728 real changes made)

. 
. reshape wide emp form inf unem nonp fwage fself iwage iself fac, ///
>     i(per state) j(exposed)
(j = 0 1)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations            1,728   ->   864         
Number of variables                  13   ->   22          
j variable (2 values)           exposed   ->   (dropped)
xij variables:
                                    emp   ->   emp0 emp1
                                   form   ->   form0 form1
                                    inf   ->   inf0 inf1
                                   unem   ->   unem0 unem1
                                   nonp   ->   nonp0 nonp1
                                  fwage   ->   fwage0 fwage1
                                  fself   ->   fself0 fself1
                                  iwage   ->   iwage0 iwage1
                                  iself   ->   iself0 iself1
                                    fac   ->   fac0 fac1
-----------------------------------------------------------------------------

. 
. *--- exposed-minus-unexposed gaps --------------------------------------------
. foreach v in emp form inf unem nonp fwage fself iwage iself {
  2.     gen double d_`v' = `v'1 - `v'0
  3. }

. 
. *--- weights, time, covariates (Update23 conventions) ------------------------
. gen double fac_tot = fac0 + fac1

. if `WTOTAL' {
.     gen double w = sqrt(fac_tot)
. }

. else {
.     gen double w = sqrt(fac1)
. }

. 
. gen year    = mod(per,100) + 2000

. gen quarter = int(per/100)

. gen t       = yq(year, quarter)

. 
. sort state

. merge m:1 state using "$build/longdiff_covariates.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               864  (_merge==3)
    -----------------------------------------

.     drop _merge

.     replace gdp_pc = ln(gdp_pc)
(864 real changes made)

.     gen region = .
(864 missing values generated)

.     replace region = 1 if inlist(state,2,3,8,10,25,26)      /*Noroeste*/
(162 real changes made)

.     replace region = 2 if inlist(state,5,19,28)             /*Noreste*/
(81 real changes made)

.     replace region = 3 if inlist(state,6,14,16,18)          /*Occidente*/
(108 real changes made)

.     replace region = 4 if inlist(state,13,21,29,30)         /*Oriente*/
(108 real changes made)

.     replace region = 5 if inlist(state,1,11,22,24,32)       /*Centronorte*/
(135 real changes made)

.     replace region = 6 if inlist(state,9,15,17)             /*Centrosur*/
(81 real changes made)

.     replace region = 7 if inlist(state,7,12,20)             /*Suroeste*/
(81 real changes made)

.     replace region = 8 if inlist(state,4,23,27,31)          /*Sureste*/
(108 real changes made)

. 
. save "ThemeH/ld_shares_2019.dta", replace
file ThemeH/ld_shares_2019.dta saved

. 
. *------------------------------------------------------------------------------
. * 2. VALIDATION: reproduce Panel A before trusting Panel C
. *------------------------------------------------------------------------------
. local SPEC "inf_pre gdp_pc school_attain i.region i.t"

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "VALIDATION vs ThemeH baseline"
VALIDATION vs ThemeH baseline

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  outcome        this build      Theme H     diff"
  outcome        this build      Theme H     diff

. 
. local ok = 1

. foreach v in emp form inf unem nonp {
  2.     quietly reg d_`v' `SPEC' [aw=w] if year == 2019, cluster(state)
  3.     scalar got_`v' = _b[inf_pre]
  4.     local  d = got_`v' - `T_`v''
  5.     di as txt "  " %-12s "`v'" as res %10.3f got_`v' ///
>        as res %12.3f `T_`v'' as res %9.3f `d'
  6.     if abs(`d') > 0.005 local ok = 0
  7. }
  emp              0.627       0.624    0.003
  form             0.904       0.903    0.001
  inf             -0.277      -0.279    0.002
  unem            -0.035      -0.035    0.000
  nonp            -0.592      -0.589   -0.003

. 
. if !`ok' {
.     di as error _n "  MISMATCH. Do not use Panel C output yet."
.     di as error "  Try: flip WTOTAL to 0; or check whether the Update26 build"
.     di as error "  restricts the sample or defines the cells differently."
.     exit 9
. }

. di as res _n "  -> PASS. Cell build matches the Table 3 specification."

  -> PASS. Cell build matches the Table 3 specification.

. 
. *------------------------------------------------------------------------------
. * 3. PANEL C: estimation with wild cluster bootstrap
. *------------------------------------------------------------------------------
. tempname pf

. postfile `pf' str12 block str8 outcome double(b se pwcb lo hi) int n ///
>     using "ThemeH/ThemeH_results_split.dta", replace

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "PANEL C ESTIMATES"
PANEL C ESTIMATES

. di as res "{hline 78}"
------------------------------------------------------------------------------

. 
. foreach v in fwage fself iwage iself {
  2. 
.     quietly reg d_`v' `SPEC' [aw=w] if year == 2019, cluster(state)
  3.     scalar b_`v'  = _b[inf_pre]
  4.     scalar se_`v' = _se[inf_pre]
  5.     local  n_`v'  = e(N)
  6. 
.     boottest inf_pre, weighttype(webb) reps(9999) seed(2026) nograph
  7.     scalar p_`v' = r(p)
  8.     matrix CI    = r(CI)
  9. 
.     post `pf' ("split") ("`v'") (b_`v') (se_`v') (p_`v') ///
>               (CI[1,1]) (CI[1,2]) (`n_`v'')
 10. 
.     di as txt "  " %-7s "`v'" as res %8.3f b_`v' ///
>        as txt "  (" as res %5.3f se_`v' as txt ")  WCB p = " as res %5.3f p_`v'
 11. }

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     9.3947
                        Prob>|t| =     0.0000

95% confidence set for null hypothesis expression: [.6531, 1.154]
  fwage     0.890  (0.095)  WCB p = 0.000

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     1.4192
                        Prob>|t| =     0.2421

95% confidence set for null hypothesis expression: [−.01116, .03706]
  fself     0.014  (0.010)  WCB p = 0.242

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =    -4.0920
                        Prob>|t| =     0.0112

95% confidence set for null hypothesis expression: [−.4301, −.09517]
  iwage    -0.281  (0.069)  WCB p = 0.011

Wild bootstrap-t, null imposed, 9999 replications, Wald test, bootstrap clustering by state, Webb weights:
  inf_pre

                           t(31) =     0.0739
                        Prob>|t| =     0.9572

95% confidence set for null hypothesis expression: [−.1374, .1442]
  iself     0.004  (0.053)  WCB p = 0.957

. postclose `pf'

. 
. *------------------------------------------------------------------------------
. * 4. ADDING-UP AUDIT
. *------------------------------------------------------------------------------
. scalar sum_f = b_fwage + b_fself

. scalar sum_i = b_iwage + b_iself

. 
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "ADDING-UP AUDIT"
ADDING-UP AUDIT

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  formal:    wage + self = " as res %7.3f sum_f ///
>    as txt "   Panel A = " as res %7.3f got_form
  formal:    wage + self =   0.904   Panel A =   0.904

. di as txt "  informal:  wage + self = " as res %7.3f sum_i ///
>    as txt "   Panel A = " as res %7.3f got_inf
  informal:  wage + self =  -0.277   Panel A =  -0.277

. 
. assert abs(sum_f - got_form) < 0.002

. assert abs(sum_i - got_inf)  < 0.002

. di as res _n "  -> PASS."

  -> PASS.

. 
. *------------------------------------------------------------------------------
. * 5. VALUES FOR THE LaTeX TABLE
. *------------------------------------------------------------------------------
. di as res _n "{hline 78}"

------------------------------------------------------------------------------

. di as res "PASTE INTO TABLE 3, PANEL C"
PASTE INTO TABLE 3, PANEL C

. di as res "{hline 78}"
------------------------------------------------------------------------------

. di as txt "  order: formal wage | formal self&other | informal wage | informal self&other"
  order: formal wage | formal self&other | informal wage | informal self&other

. foreach v in fwage fself iwage iself {
  2.     local st ""
  3.     if p_`v' < 0.10 local st "*"
  4.     if p_`v' < 0.05 local st "**"
  5.     if p_`v' < 0.01 local st "***"
  6.     di as txt "  " %-7s "`v'" as res %5.2f b_`v' "`st'" ///
>        as txt "  (" as res %4.2f se_`v' as txt ")  [" as res %5.3f p_`v' as txt "]"
  7. }
  fwage   0.89***  (0.09)  [0.000]
  fself   0.01  (0.01)  [0.242]
  iwage  -0.28**  (0.07)  [0.011]
  iself   0.00  (0.05)  [0.957]

. 
. *==============================================================================
. * END
. *==============================================================================
. 
. * Run the Section 1 build four times, changing only these two switches,
. * and compare the validation block against 0.624 / 0.903 / -0.279.
. *   (a) WTOTAL 1, with    "drop if clase1==0"   <- what you just ran: 0.627/0.904/-0.277
. *   (b) WTOTAL 1, without "drop if clase1==0"
. *   (c) WTOTAL 0, with
. *   (d) WTOTAL 0, without
. * Whichever reproduces Theme H to three decimals is the Update26 convention.
. * Quick way to see if the drop is the culprit before rerunning anything:
. use "$build/panel_16_22.dta", clear

. drop if inrange(cohort,1999,2000) | cohort < 1995
(1,033,327 observations deleted)

. gen byte exposed = inrange(cohort,2001,2004)

. gen year = mod(per,100)+2000

. tab cohort clase1 if year==2019 & clase1==0    // who is being dropped
no observations

. count if year==2019 & clase1==0 & exposed==1
  0

. count if year==2019 & clase1==0 & exposed==0
  0

. 
. use "ThemeH/ld_shares_2019.dta", clear

. keep if year == 2019
(736 observations deleted)

. 
. di as txt _n "2019 levels, percent of cohort population:"

2019 levels, percent of cohort population:

. di as txt "  outcome    exposed   unexposed"
  outcome    exposed   unexposed

. foreach v in emp form inf unem nonp {
  2.     quietly sum `v'1 [aw=fac1]
  3.     local e = r(mean)
  4.     quietly sum `v'0 [aw=fac0]
  5.     local u = r(mean)
  6.     di as txt "  " %-8s "`v'" as res %9.1f `e' as res %11.1f `u'
  7. }
  emp          21.3       56.2
  form          1.6       23.9
  inf          19.7       32.3
  unem          1.5        4.5
  nonp         77.1       39.4

. 
. * formality rate (formal as share of employed), for the "7.6 percent" claim
. foreach g in 1 0 {
  2.     quietly sum form`g' [aw=fac`g']
  3.     local f = r(mean)
  4.     quietly sum emp`g'  [aw=fac`g']
  5.     local e = r(mean)
  6.     di as txt "  formality rate, exposed==`g': " as res %5.1f 100*`f'/`e'
  7. }
  formality rate, exposed==1:   7.6
  formality rate, exposed==0:  42.5

. 
end of do-file

. do "/var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//SD22909.000000"

. use "ThemeH/ld_shares_2019.dta", clear

. gen double w_exp = sqrt(fac1)          // exposed-cohort population only

. 
. di as txt "  outcome   w=sqrt(total)  w=sqrt(exposed)   ThemeH"
  outcome   w=sqrt(total)  w=sqrt(exposed)   ThemeH

. foreach v in emp form inf unem nonp {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>         [aw=w] if year==2019, cluster(state)
  3.     local a = _b[inf_pre]
  4.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>         [aw=w_exp] if year==2019, cluster(state)
  5.     local b = _b[inf_pre]
  6.     di as txt "  " %-8s "`v'" as res %12.3f `a' %16.3f `b'
  7. }
  emp            0.627           0.624
  form           0.904           0.903
  inf           -0.277          -0.279
  unem          -0.035          -0.035
  nonp          -0.592          -0.589

. 
end of do-file

. do "/var/folders/0p/b0pkqswj5zbbg_14jnr4pgvr0000gn/T//SD22909.000000"

. use "ThemeH/ld_shares_2019.dta", clear

. gen double w_exp = sqrt(fac1)          // exposed-cohort population only

. 
. di as txt "  outcome   w=sqrt(total)  w=sqrt(exposed)   ThemeH"
  outcome   w=sqrt(total)  w=sqrt(exposed)   ThemeH

. foreach v in emp form inf unem nonp {
  2.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>         [aw=w] if year==2019, cluster(state)
  3.     local a = _b[inf_pre]
  4.     quietly reg d_`v' inf_pre gdp_pc school_attain i.region i.t ///
>         [aw=w_exp] if year==2019, cluster(state)
  5.     local b = _b[inf_pre]
  6.     di as txt "  " %-8s "`v'" as res %12.3f `a' %16.3f `b'
  7. }
  emp            0.627           0.624
  form           0.904           0.903
  inf           -0.277          -0.279
  unem          -0.035          -0.035
  nonp          -0.592          -0.589

. 
. use "ThemeH/ld_shares_2019.dta", clear

. keep if year==2019
(736 observations deleted)

. xtile Iq = inf_pre [aw=fac_tot], n(4)

. table Iq, stat(mean inf_pre form1 form0 d_form fwage1 fwage0)

------------------------------------------------------------------------------------------
                       |   inf_pre     1 form     0 form      d_form    1 fwage    0 fwage
-----------------------+------------------------------------------------------------------
4 quantiles of inf_pre |                                                                  
  1                    |  43.07268   3.117421   36.87038   -33.75296   3.104248   36.18399
  2                    |  54.84767   1.977134   27.28485   -25.30772   1.947475   26.47479
  3                    |  63.73531   .9389554   18.18299   -17.24404   .8889602   17.63739
  4                    |   75.4408   .5576167    10.6392   -10.08159   .5267796   10.04313
  Total                |  57.52668   1.799044   24.66318   -22.86413    1.76971   24.00855
------------------------------------------------------------------------------------------

. * is d_form monotone in Iq, and are form1/form0 plausible at both extremes?
. 
end of do-file

. do "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IMS
> S/Update26/ThemeH/Table3_final.do"

. ********************************************************************************
. * TABLE 3 -- FINAL BUILD
. * School-Linked Social Insurance and Labor Market Effects: Evidence from Mexico
. *
. * PURPOSE: produce every number in Table 3 (Panels A-D), its table note, the
. * leverage statistics for footnote 10, and the income placebo referenced by
. * footnote 10 -- all from ONE pipeline under ONE weight convention, so the
. * published table has a single reproducible source.
. *
. * WEIGHT CONVENTION: square root of TOTAL cell population, sqrt(fac0+fac1).
. * This matches Table 2 (Tienes_IMSS_Update23.do collapses by(per state) and
. * sets w = sqrt(fac)), so the note wording "square root of the cell population"
. * is accurate for both tables.
. *
. * SUPERSEDES:
. *   - ThemeH (used sqrt(fac1), exposed-cohort population only)
. *   - ThemeA Sections 3-4B: its collapse was
. *         collapse ... (sum) fac [pw=fac]
. *     and Stata's (sum) APPLIES the weight, so pop_ = sum(fac^2), not the cell
. *     population. Fixed here by summing fac with no weight attached.
. *
. * NOTE ON clase1==0: not dropped. Those observations fall outside the PEA/PNEA
. * universe and are counted as non-participants, as in ThemeH. In 2019 there are
. * none, so the choice is immaterial for this table; it is stated for the
. * replication package.
. *
. * OUTPUT
. *   Table3/table3_cells.dta      cell-level audit trail
. *   Table3/table3_results.dta    all coefficients
. *   Table3/Table3_summary.txt    READ THIS -- paste-ready values
. ********************************************************************************
. 
. clear all

. set more off

. set seed 123

. 
. global enoe     "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projec
> ts/ENOE"

. global update23 "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projec
> ts/Tienes IMSS/Update23"

. global update26 "/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projec
> ts/Tienes IMSS/Update26"

. 
. cd "$update26"
/Users/alainpineda/Library/CloudStorage/GoogleDrive-alainpp25@gmail.com/My Drive/PhD/Projects/Tienes IMSS/Upda
> te26

. cap mkdir Table3

. cap log close _all
