Skip to main content

occu-choice-pf

Tables for the survey experiment of Perceived Wage Differences and Early Career Job Search Choices. The functions are written and tested locally against simulated data, then run on the actual data. All numbers in this package come from simulated data.

Use

from occu_choice_pf import regressions as reg, save_tex, setup_log

setup_log(log_folder, 'regressions')      # logs the package version first
save_tex(reg.reg_control_table(long), out / 'tab_poisson.tex')               # Poisson
save_tex(reg.reg_control_table(long, method='ols'), out / 'tab_ols.tex')     # OLS

Tables return a bare tabular in the style of the paper's tables (the \sym stars of esttab included); save_tex writes it and logs it, so it can be read before an export request. Defaults (variables, labels) sit in occu_choice_pf.labels and can be overridden per call. See the docstrings, and examples/ for every exhibit and for custom tables.

The table of controls

reg_control_table(long) regresses each outcome on T_vj_vij_job, one panel per outcome, with one table column per entry of cols_control. Every column has coefs (reported), common_control, and the controls of its entry. The defaults (labels.COLS_CONTROL, labels.COMMON_CONTROL) give:

Column Controls cols_control entry
(1) vj_vij_job and the person fixed effect (common_control) {}
(2) + vj_vij_job squared and cubed POWERS
(3) + pre-treatment controls times vj_vij_job {**POWERS, **PRE_CONTROLS}
(4) (3) + education field dummies times vj_vij_job {**POWERS, **PRE_CONTROLS, **EDUC_FIELD}
(5) (3) + DISCED (disced_6d) dummies times vj_vij_job {**POWERS, **PRE_CONTROLS, **DISCED}

A control is {check-mark row label: terms}, and a term is a column ('age'), a column made into a dummy for each value ('i.age', as Stata's i.), or a polars expression (c.vj_vij_job ** 2). Your own columns:

from occu_choice_pf.labels import DISCED, POWERS, TIMES_MIS
own = {'Age dummies, gender ' + TIMES_MIS: ['i.age', 'female']}
reg.reg_control_table(long, cols_control=[{}, POWERS, {**POWERS, **own}, {**own, **DISCED}])

Every term of cols_control is times vj_vij_job, except one wrapped in reg.plain(), which enters its column as it is; an i.<column> there is a fixed effect absorbed in that column only:

from occu_choice_pf.labels import JOB
reg.reg_control_table(long, cols_control=[{}, {'Job type FE': reg.plain('i.' + JOB)}])

The arguments, the check-mark rows and the input checks are in help(reg.reg_control_table); the estimation, and what drops out of a column (all of it logged), in help(reg). reg.reg_control_fits(long, ...) returns the pyfixest fits behind a table, {outcome: [fit per column]}, to look into with .summary() or pf.etable. examples/ has custom calls: a subsample, other regressors, clustering and a second fixed effect.

The columns of a panel can rest on different rows: the Poisson regression with the DISCED dummies drops the separated rows of persons alone in their DISCED, which the other columns keep. common_sample=True estimates every column on the rows all of them keep, so that the columns differ in their controls only; reg.reg_control_samples(long, ...), with the arguments of the table, returns long with a Boolean column in_<outcome>_<column> per regression, True in the rows it is estimated on:

save_tex(reg.reg_control_table(long, common_sample=True), out / 'tab_poisson_common.tex')
s = reg.reg_control_samples(long)
s.filter(c.in_appl_job_5)                      # the rows of panel B, column (5)

A separated row leaves the person's other rows in: with vj_vij_job winsorized, a person alone in their DISCED whose rows with applications are tied at the bound keeps those. drop_persons='separated' drops a person with a separated row whole, and drop_persons='any' a person who loses any row, for a missing value, separation or pyfixest; both take the arguments above too:

save_tex(reg.reg_control_table(long, drop_persons='separated'), out / 'tab_poisson_sep.tex')
save_tex(reg.reg_control_table(long, drop_persons='any'), out / 'tab_poisson_whole.tex')

share_range=(low, high) keeps the persons of a major (share_educ, by default disced_6d) only where its treated share among the persons of the regression, after separation and pyfixest's drops, is from low to high. The persons of the other majors are dropped whole and the regression refit until every major left is in the range. Each table column and outcome has its own sample, and so its own shares:

save_tex(reg.reg_control_table(long, share_range=(0.1, 0.9)), out / 'tab_poisson_share.tex')

totals={outcome: row label} adds a row between Individuals and N in that outcome's panel: the outcome summed over the rows each column is estimated on, left empty where fewer than 5 persons (min_n) have an outcome above 0:

reg.reg_control_table(long, totals={'appl_job': 'Applications'})   # the applications made

method takes {outcome: 'ols' | 'poisson'} too, for every outcome, so that panels can differ in their estimator. counts={row label: polars expression} describes the input sample at the end of the table, under the check-mark rows: each expression is evaluated on the frame given (NaN as missing) and its number shown in every column, $<$5 below min_n. The panels then show N but not Individuals; panel_n=False leaves out N too:

outcomes = {'piij': 'Log likelihood of applying, $' + PI + '$',
            'appl_job': 'Number of applications to the job type in 3 months',
            'spell_1_new_job': 'Found a job in the job type ($>$100h)'}
counts = {'Individuals who find a job': c.pnr.filter(c.spell_1_new_job > 0).n_unique(),
          'Individuals who log an application': c.pnr.filter(c.appl_job > 0).n_unique(),
          'Applications': c.appl_job.sum(),
          'Individuals': c.pnr.n_unique()}
reg.reg_control_table(long, outcomes, cols_control=[{}, PRE_CONTROLS, {**PRE_CONTROLS, **DISCED}],
                      method={'piij': 'ols', 'appl_job': 'poisson', 'spell_1_new_job': 'poisson'},
                      counts=counts)

An expression must give one number (an aggregate, such as .sum() or .n_unique()). A sum must rest on 5 persons or more, and so must the difference of two counts of persons, one group within the other (persons less those who find a job): neither is checked.

panels=False gives each column an outcome of its own, in one panel: the j-th outcome with the j-th entry of cols_control, its title under the column's number (esttab style). A coefficient of coefs that is also a term in reg.plain() of cols_control enters only the columns that have it, and its row is empty in the others (its control has no check-mark row). constant=False leaves the constant out of a column without a fixed effect (OLS only). The acceptance tables below use all three:

reg.reg_control_table(long, {'y1': 'Y1', 'y2': 'Y2'}, coefs={'w': 'Wage', 'p': 'Offer'},
                      cols_control=[{}, {'Offer': reg.plain('p')}], panels=False)
# (1) y1 on w; (2) y2 on w and p

The treated share within majors

With the major dummies times vj_vij_job (columns 4 and 5), the treatment effect is estimated within majors: a major whose persons are all treated, or all in the control group, adds next to nothing, and a major weighs more the closer its treated share is to one half. Without them, a treated share that differs between majors moves the estimate where the slope on vj_vij_job differs between majors. treatment_shares shows how large the persons' majors are and how far the treated share of their major is from what random assignment gives (T permuted across the persons, 1000 draws, no strata). Three table columns or a plot per column of labels.EDUC: major field and DISCED. The functions take the persons frame, one row per person, and raise on a person with more than one row:

from occu_choice_pf import save_fig
from occu_choice_pf import treatment_shares as ts

save_tex(ts.percentile_table(persons), out / 'tab_share_percentiles.tex')
save_fig(ts.share_figure(persons), out / 'fig_share_hist.png')
ts.share_frame(persons, 'disced_6d')  # one row per major: on the server only
  • percentile_table: percentiles over persons of the size of their major and of its treated share (data and random assignment). Each percentile is the mean of the 9 persons around it (window), never one person's value. Below them, the standard deviation over persons of the treated share of their major (data and random assignment) and its p-value under random assignment: a permutation chi-squared test of treatment by major.
  • share_figure: a histogram of the persons by the treated share of their major (0, ten intervals, 1), with the mean and the 95% range of random assignment; a matplotlib figure, the numbers plotted in the log. save_fig writes it, a PNG at 300 dpi unless the path ends in .pdf.

The persons are those of the frame given, so the persons of a regression, persons.join(s.filter(c.in_appl_job_5), on='pnr', how='semi') with s = reg.reg_control_samples(long), give the shares within it.

Disclosure: no number shown rests on fewer than min_n (5) persons, nor can one be worked out from the others, the persons treated (in the paper's balance table) included. A count below 5, 0 included, reads <5. Percentiles are left empty where their 9-person windows overlap or leave 1-4 persons outside; the shares, the test and random assignment, which depends on the persons treated, with fewer than 5 treated or untreated. A bar of fewer than 5 persons reads <5; the bars at 0 and 1 are left out where the persons in all-treated or all-control majors, or the treated or untreated of the others, are 1-4; where the bars left out add up to 1-4 persons, the smallest interval bar is left out too. A 0 can still be worked out. share_frame lists every major, however small, and is for the server only.

The slopes of the majors

major_slopes estimates the coefficient on T_vj_vij_job for each major (i.disced_6d#T_vj_vij_job) and shows how the pooled estimate weighs them, so that one can see whether the major dummies times vj_vij_job move the estimate through the slopes of the majors or through their weights. Per outcome, four regressions with the person fixed effect, all on the same rows (those every one of them keeps, refit until none drops another):

Regression Regressors Estimate
common T_vj_vij_job, vj_vij_job pooled b, column (1) of reg_control_table
major T_vj_vij_job, major dummies times vj_vij_job pooled b'
common_d major dummies times T_vj_vij_job (majors with treated individuals), vj_vij_job b_m
major_d major dummies times T_vj_vij_job (majors with treated and control individuals), major dummies times vj_vij_job b'_m

Each pooled estimate is exactly a weighted mean of the majors' slopes, b = Σ w_m b_m and b' = Σ w'_m b'_m: w_m is the sum over the major's rows of L r T_vj_vij_job, scaled to add up to 1, where r is the residual of T_vj_vij_job on the other regressors of the pooled regression, weighted by L. L is 1 in OLS and in Poisson the logarithmic mean of the two regressions' fitted means, as the two sets of first-order conditions give. In OLS with no other controls, w_m is the major's share of the treated individuals' within-person variance of vj_vij_job, and w'_m is proportional to that variance in the major times s(1 − s), s the treated share of it: 0 where a major has one arm only. So adding the major dummies times vj_vij_job changes two things at once: what the treated individuals of a major are compared with (all control individuals, or those of their own major) and how much each major counts. The table walks from b to b' one step at a time and shows the estimate after each: (1) only the majors with treated and control individuals (both arms of the experiment), weighted as in b; (2) their slopes b_m weighted as in b'; (3) each major against its own control individuals, b'_m, which gives b'; and (4) those b'_m weighted as in b again, a step of the weights alone, which shows b' weighted as b is. A large move at (2) means the weights change; at (3), that treated individuals are in majors whose control slope differs from the common one (in OLS b_m − b'_m is exactly that difference), which the major dummies times vj_vij_job correct; at (1), that the majors without control individuals move b.

from occu_choice_pf import major_slopes as ms
from occu_choice_pf.labels import POWERS, PRE_CONTROLS

save_tex(ms.slope_table(long), out / 'tab_major_slopes.tex')                    # Poisson
save_tex(ms.slope_table(long, method='ols'), out / 'tab_major_slopes_ols.tex')  # OLS
save_tex(ms.slope_table(long, controls={**POWERS, **PRE_CONTROLS}), out / 'tab_major_slopes_3_5.tex')
save_tex(ms.slope_table(long, bootstrap=200, workers=20), out / 'tab_major_slopes_se.tex')  # p-values
save_fig(ms.slope_figure(long), out / 'fig_major_slopes.png')                   # for export
save_fig(ms.slope_figure(long, raw=True), out / 'fig_major_slopes_raw.png')     # server only
ms.slope_frame(long).sort('b_common')                                           # server only
save_tex(ms.split_half_table(long), out / 'tab_major_slopes_noise.tex')         # an extra
  • slope_table: one column per outcome. A: the two pooled estimates and their difference, the second less the first; B: the path from the first to the second, the estimate after each step (labels.SLOPE_PATH); C and D: the mean slope of the majors, each major once, by its individuals and by its regression weight (which is the pooled estimate again), and the majors with a slope. bootstrap=B gives the difference a standard error and stars, and each step a row under it with the p-value of its change from the row above, from B draws of individuals with replacement, each draw running the four regressions and the weights anew (an individual drawn twice is two individuals); the log compares the bootstrap standard errors of the pooled estimates with the clustered ones. A draw takes some 1.5 seconds per outcome in Poisson with 340 majors. workers=20 estimates the draws in 20 processes at once, one thread each, so that 200 draws take a minute or two on the server's 20 cores (on 14 cores, 112 draws took 81 seconds rather than 5.5 minutes); the seed fixes the draws before any is estimated, so the numbers are those of workers=1. Windows starts each worker by importing the script that calls it: in the VS Code Interactive window that needs nothing, but a script run from the command line must have its work under if __name__ == '__main__':, as examples/major_slopes/code/run_major_slopes.py does, or each worker runs it all again.
  • slope_figure: histograms of the majors' slopes, a block per outcome, a row per pooled regression and a column per weighting (each major once, by its individuals, by its regression weight), with the pooled estimate and the mean slope of the majors. For export each major, sorted by slope, is drawn at a moving average: the mean slope of the majors around it, the window widened on both sides until it holds 5 treated individuals (and 5 control individuals for b'_m), and with the mean weight of the window, so that no bar is the weight of a major of a few; a major as large draws its own slope and weight. As two overlapping windows give single values back, the averages are neither shown nor logged, only the bars, whose intervals have a round width from a multiple of it, so that the ends of the axis are not values either. smooth='groups' draws groups of majors that do not overlap instead, each at its mean. raw=True draws each major at its own slope, where outliers show, and says on the figure that it is for the server only.
  • slope_frame: one row per outcome and major with its individuals by arm, slopes, standard errors, weights and control slope; for the server only.
  • split_half_table (an extra): how much of the spread of the slopes across majors is real. The individuals of each major and arm are split at random into two halves (20 times), the slopes estimated in each half, and their covariance across majors, which leaves out the noise, independent between the halves, compared with the variance of the slopes of the whole sample: per weighting, the standard deviation of the slopes, that of the true slopes, and the share of the variance that is real with its standard error. Majors need 3 individuals per arm in each half (min_half). It is noisy with few majors: read the share against its standard error.

controls= takes an entry of cols_control (terms times vj_vij_job, reg.plain() as they are) and adds it to all four regressions; the weights stay exact. The log gives the gap between each pooled estimate and the weighted mean of the slopes (1e-8 or less in Poisson, 1e-16 in OLS) and warns above 1e-6, which means a regression did not converge. As in an Oaxaca decomposition, the split between the weights and the slopes parts depends on which comes first. The table's order keeps the noise of a major's own control slope, large where it has few control individuals, out of the weights part and weighs it little in the slopes part; the other order, the weights at b'_m and the slopes weighed as in b, puts it into both with opposite signs (on fake data -0.22 and 0.20 against -0.02 and 0.00). The log gives the other order too.

Disclosure: every number of the table rests on all the individuals of its column. Where 1-4 treated individuals are in majors without control individuals, the step that leaves them out would rest on them: its line is left empty and the path takes it together with the next (in every bootstrap draw too). Where no major lacks control individuals the step changes nothing, and its line is left out. The counts of majors rest on majors, not individuals, and are shown.

The attrition table

attrition.attrition_table(df) asks whether getting to the end of the survey depends on the treatment, alone, by major or by misperception. T is drawn when a person starts the survey, and the pages before the treatment page are the same in both arms, so the attrition that can bias the estimates is among those who reached it; reaching it, among everyone who started, is a placebo. It takes one row per person:

from occu_choice_pf import attrition as at
from occu_choice_pf.labels import COLS_PLACEBO, TEST_PLACEBO

save_tex(at.attrition_table(started.filter(c.T_page == 1)), out / 'tab_attrition.tex')
save_tex(at.attrition_table(started, {'T_page': 'Reached the treatment page'}, TEST_PLACEBO,
                            COLS_PLACEBO), out / 'tab_attrition_placebo.tex')

Linear probability models (pyfixest feols, standard errors clustered on the person), one panel per outcome (labels.ATTRITION_OUTCOMES: full_answer and primary_sample, each 0 or 1 for every person). Each table column has two entries, one in each of two lists of the same length:

  • test_coefs=[[terms], ...]: the terms the column tests. They are the top rows of the table, a number by its coefficient and a fixed effect by a check mark, and under them the p-value of the test that they are all 0 and which test it is.
  • cols_control=[{label: terms}, ...]: the column's background controls, check-mark rows at the bottom, as in reg_control_table.

Every term enters as it is written, and nothing is added: a column, a polars expression, 'i.<column>' for a fixed effect per value, or 'i.<a>#<b>' for one per value of a and b together ('i.disced_6d#T', the major-by-arm cells). Interactions with T are written out, and their main effects go in the background. The defaults (labels.TEST_COEFS, labels.COLS_ATTRITION):

Column Tested (top) Background (bottom)
(1) T none
(2) T major FE
(3) T major FE, pre-treatment controls
(4) 'i.disced_6d#T', major by arm T, major FE, pre-treatment controls
(5) T times the misperception, and times its absolute value T, the misperception and its absolute value, major FE, pre-treatment controls

test_labels={term: row label} (labels.TEST_LABELS) names the top rows, a column or fixed effect by how it is written, an expression by its alias. Pre-treatment controls as fixed effects are i.<column> terms:

from occu_choice_pf.labels import MAJOR_FE
controls = {**MAJOR_FE, 'Pre-treatment controls': [*linear, 'i.age']}
save_tex(at.attrition_table(exposed, test_coefs=[['T']], cols_control=[controls]), out / 'tab.tex')
# do the majors predict attrition? Their joint F test
at.attrition_table(exposed, test_coefs=[['i.disced_6d']], cols_control=[{}])

The joint test is one of three:

  • Wald, tested terms that are all numbers: pyfixest's Wald test with the robust variance (chi-squared; one term, its t-test, as its stars).
  • F, tested terms with a fixed effect: the classical F test of the fit with them against the background alone, each fit's parameters the rank of its regressors with a dummy per fixed-effect group, so that a fixed effect nested in or overlapping another counts once (the robust variance is degenerate where a group has one person).
  • Permutation: T permuted within majors (strata, DISCED by default) draws times (1000), every term written with T computed anew, the statistic the residual sum of squares without the tested terms over that with them. Exact under the sharp null that T changes no one's outcome. The tested terms must be written with T (T, an expression of T, i.<a>#T): a column made from T before the call would not change with the draws.

Where the tested terms add nothing beside the background controls (pyfixest drops them as collinear), no test is run and its cells are empty; the log says so.

permutation chooses: None (the default) gives the permutation test to a column whose tested terms include a fixed effect written with T, the major-by-arm cells, where the analytical tests over-reject: some major has one person per arm. With no effect of T, the robust Wald test of the major-by-arm dummies rejected at 5% in 10 to 23% of simulated draws, the classical F test in up to 9%, and the robust Wald test of the misperception times T in 2.5 to 7%. True or False sets every column, a list each. The permutation takes a few minutes per outcome at 1000 draws.

Every column shows its R² and adjusted R² (pyfixest's), so column (2) against (1) says how much the majors predict attrition. With hundreds of small majors the fixed effects raise the R² by about majors / persons even where they predict nothing, which the adjusted R² takes out: it counts each fixed-effect group as a parameter. A background control constant within the groups of a tested fixed effect (the major FE and T within the major-by-arm cells) is left out of the fit with the tested terms, so that it counts once; pyfixest otherwise counts overlapping fixed effects twice. Persons alone in a fixed effect are kept, so the persons of a column are the same with and without the tested terms. A person missing a term that enters as a number leaves that column (the log says how many); in a fixed effect, i.<column>, a missing value (null or NaN) is a group of its own and the person stays. The log has every tested coefficient.

Disclosure: a column is left empty unless 5 persons or more (min_n) of each arm have each value of the outcome, as the control mean and a coefficient on T alone give the share of each arm; Individuals reads <5 below 5. A tested fixed effect's check mark shows anyway.

The table of wage gap underestimation

underestimation_gap.gap_table(rows) is Table 3 of the paper: one row per subsample, rows={label: frame}, each frame the extra-long frame or a subsample of it, made with polars before the call.

from occu_choice_pf import underestimation_gap as ug

clean = {'d_vj_vij': c.d_vj_vij_clean, 'd_Vj_Vij_rate': c.d_Vj_Vij_rate_clean}
rows = {
    'Full sample': elong,
    **{f'Actual log wage gap $>$ {x}': elong.filter(c.d_vj > x) for x in [0.05, 0.1]},
    'Full sample, correcting reporting errors': elong.with_columns(**clean),
    'Reweighted for non-participation': elong,
}
weights = {'Reweighted for non-participation': 'weight_invited'}
save_tex(ug.gap_table(rows, weights), out / 'tab_estimation_gaps.tex')
save_tex(ug.gap_table(rows, weights, bootstrap=1000), out / 'tab_estimation_gaps_se.tex')

The rows are numbered. bootstrap=B adds standard errors from B draws of persons with replacement. compare=[(label, label)] puts the p-value of the difference between two rows under them ($p$-value of difference (1)-(2)), and a line under that. The rows need not be next to each other, and a row may be in several pairs: compare=[('Men', 'Women'), ('Men', 'Women, reweighted to (1)')] puts both p-values under the three rows (the rows from the first to the last of a pair are a block, joined with the blocks it overlaps). p_at_end=True puts all the p-values in the last rows of the table instead. share_column sets column 7: 'underestimator' (the default), the share of individuals who are underestimators; 'zero_gap', the share of job pairs with no perceived wage gap (d_Vij == 0); a list of both, ['underestimator', 'zero_gap'], columns 7 and 8 in that order; or None, no column 7. The frames need not have a column not shown. A frame with NaN raises, since a filter such as c.d_vj > 0.05 keeps NaN: make it missing in prep, elong = elong.with_columns(pl.col(pl.Float64).fill_nan(None)). ps_group reweights one group to the other with a propensity score model estimated anew in each draw, as Table C1 of the parental transmission paper: it adds ps_weight (reweighted to the other group) and ps_support (1 for persons with a weight) to every row, to name in weights:

no, yes = elong.filter(c.par_anyjobtype == 0), elong.filter(c.par_anyjobtype == 1)
rows = {'Neither': no, 'Either': yes, 'Neither, weightable': no, 'Either, reweighted to (3)': yes}
ug.gap_table(rows, {'Neither, weightable': 'ps_support', 'Either, reweighted to (3)': 'ps_weight'},
             bootstrap=1000, ps_group='par_anyjobtype',
             compare=[('Neither', 'Either'), ('Neither, weightable', 'Either, reweighted to (3)')])

The model is a logit of ps_group on ps_xs with the fixed effects ps_fes (majors, disced_6d, by default), in pyfixest; with one fixed effect and no ps_xs it is the group's share in each major. The cells, the weights and what is left out are in help(ug.gap_table) and help(ug.ps_weights).

The wage elasticity from the acceptance questions

The acceptance tables estimate the wage elasticity of applications, beta = delta / sigma, from the two survey questions on accepting offers, as in the acceptance note (AcceptModel2026, Sections 5.2-5.4; equations numbered as there). Job seekers report the likelihood of accepting an offer from each job type when all three offer the wages they expect, pi^A (phiij, in logs), and when all three offer the middle one, pi^AE (phi_samew_ij). Comparing the two removes the perceived amenities, which they share. The tables are reg_control_table calls with an outcome per column (panels=False), in examples/acceptance/code/run_acceptance.py:

Column Outcome Regressors Long frame, person FE Pairs (d_), no constant
(1) pi^A - pi^AE w~ Eq. (3) Eq. (5)
(2) pi^A w~, pi^AE Eq. (3), tau free Eq. (6)
(3) pi - pi^AE w~, p~ Eq. (7) (7) in pairs
(4) pi w~, p~, pi^AE Eq. (8) (8) in pairs (5.4.5)

piij is the log likelihood of applying (pi), wij the perceived log own wage (w~) and pij the perceived log probability of an offer (p~); the pairs use d_<column>, job j less job j'. Every column is OLS, clustered on the person. The coefficient on the wage is beta in every column, that on pij 1/sigma, and the model puts the one on phi_samew_ij, tau, at 1. The pair regressions have no constant (constant=False), as the note's: each pair is in the frame in both orders, so a constant would be 0, and where every person has all three job types the pairs give the coefficients of the fixed effect regressions (the note's 5.4.3). The labels are those of the paper's tables, with the note's notation: the rows in labels.W_ROW, P_ROW, PI_AE_ROW, D_W_ROW, D_P_ROW, D_PI_AE_ROW, the outcomes heading the columns in labels.ACCEPT_TITLES and PAIR_TITLES, and labels.PERSON_FE ("Individual FE").

The long frame

One row per person and job type (pnr x type_sizerank_job), with the columns of misc_docs/all_waves_long_variable_definitions.txt: T, vj_vij_job, T_vj_vij_job, the pre-treatment variables in labels.PRETREATMENT, educ_field, disced_6d, and the outcomes in labels.OUTCOMES: spell_1_new_job (1 for the job type of the first new job after the survey) and appl_job (the number of applications to the job type). The acceptance tables use phiij, phi_samew_ij, piij, wij and pij.

The persons frame

One row per person (pnr), with the columns of the long frame that take one value per person: T, the pre-treatment variables and the education columns. treatment_shares uses T, educ_field and disced_6d.

The extra-long frame

One row per person and ordered pair of job types (pnr x type_sizerank_job x type_sizerank_jobj), each pair in both orders; a d_ column is job j minus job j'. gap_table uses d_Vj_Vij_rate, d_vj_vij, d_v_vi_max_notmaxV_rate (one value per person) and, to reweight, disced_6d; the acceptance tables use d_phiij, d_phi_samew_ij, d_piij, d_wij and d_pij.

The frame of everyone who started

One row per person who started the survey (pnr): T for everyone, the last page reached index_in_pages, T_page (it is 14 or more: the treatment page) and full_answer (it is 30: finished), primary_sample (in the study sample: finished, and no expected wage of 0), education, the pre-treatment controls and d_v_vi_max_notmaxV. The answers before the treatment page are there for everyone who reached it.

Tests on the server data

The tests are installed with the package, and pytest with them. After prep, run them from the server script:

occu_choice_pf.run_tests({'long': long, 'persons': persons, 'elong': elong, 'attrition': started})

The data tests of a frame left out are skipped.

It logs pytest's output as it comes, so it shows on screen and is in the log file of setup_log, and returns 0 if every test passes. The frame is written to a temporary folder, deleted afterwards, and the tests run in a new process. Further arguments go to pytest: run_tests(frames, '-m', 'data') runs the data tests only. It skips the test that compiles the tables with latexmk, since LaTeX on the server differs.

The data tests (tests/test_regressions_data.py, marked data) check what the table assumes of its input but cannot check itself, and build both default tables:

  • one row per person and job type;
  • the outcomes, coefficients and controls are numbers or Booleans;
  • T, the pre-treatment controls and the education columns take one value per person;
  • T is 0 or 1, and T_vj_vij_job is T * vj_vij_job, missing (null or NaN) where vj_vij_job is;
  • the pre-treatment controls have no missing values, so that the columns of a panel rest on the same rows but for what the Poisson regression drops;
  • the outcomes are at least 0;
  • both default tables build and keep T_vj_vij_job and vj_vij_job in every column, and pyfixest's estimation sample, whose persons the Individuals row and min_n count, has the fit's N rows and carries the row numbers that common_sample and reg_control_samples read (a check on the server's pyfixest version).

tests/test_treatment_shares_data.py checks that persons has one row per person, T and the education columns, and, with long given too, the same persons as long with the same T and education (the exhibits read them from persons, the regressions from long); and it builds the exhibits of treatment_shares.

tests/test_major_slopes_data.py checks, on long, that the weights give the pooled estimates back (they do where the regressions converge), and builds the exhibits of major_slopes.

tests/test_acceptance_data.py checks that long has one row per person and job type and elong one per person and ordered pair; that the columns of the acceptance tables are numbers and finite (no log of 0); that every pair is in elong in both orders, with each d_ column of (j', j) minus that of (j, j') and missing in both or neither; and with both frames given, that each d_ column is the long column of j less that of j'.

tests/test_attrition_data.py checks that attrition has one row per person; that T, T_page, full_answer and the outcomes are 0 or 1 for everyone; that T_page and full_answer are the page reached (14 or more, 30); that primary_sample is 1 only for persons who finished; it warns, with the number, where a pre-treatment control or the misperception is missing for persons who reached the treatment page (the table leaves them out of the columns where it enters as a number; as a fixed effect, missing is a group of its own); with persons given too, that each person of the study sample is in it, finished, with the same T and education; and it builds both tables.

A failed data test shows the offending values. The other tests check the code on fake data; they give the same result anywhere, so on the server they test the environment.

Layout

src/occu_choice_pf/
├── functions/          one module per topic: regressions.py, labels.py, utils.py
│                       underestimation_gap.py, treatment_shares.py, attrition.py,
│                       major_slopes.py;
│                       imported from the top:
│                       from occu_choice_pf import regressions
├── simulation/         fake data per module (regressions.py) and the files in data/
├── examples/
│   └── regressions/    code/ runs every table on the fake data;
│                       logs/ and output/ hold what it writes
└── tests/              test_<module>.py for the code, test_<module>_data.py
                        for what must hold on the server frames

simulation/, examples/ and tests/ are installed with the package. To find them:

python -c "import occu_choice_pf, pathlib; print(pathlib.Path(occu_choice_pf.__file__).parent)"
python <that folder>/examples/regressions/code/run_regressions.py <output folder>

Every example also runs in the VS Code Interactive window, whole or cell by cell (# %%).

Adding a module

  1. functions/<name>.py: importable at once as occu_choice_pf.<name>; arguments as {column: label} dicts, with defaults in labels.py
  2. simulation/<name>.py: simulate(), save(), load()
  3. examples/<name>/code/run_<name>.py, plus logs/.gitkeep. Take the output folder from root = example_root('<name>'), and split sections with # %%. tests/test_examples.py runs every example.
  4. tests/test_<name>.py for the code, and tests/test_<name>_data.py, marked data, for what the functions assume of real frames.

Development

uv sync                                          # environment in .venv
uv run pytest -n auto                            # also compiles the LaTeX if latexmk is found
uv run python src/occu_choice_pf/simulation/regressions.py   # save the fake data to simulation/data
uv run pytest --data src/occu_choice_pf/simulation/data      # data tests on saved frames

-n auto runs the tests on all cores (pytest-xdist, in the dev group only). The lower bounds in pyproject.toml are the server's versions for loguru, numpy, polars and scipy (as for ad-data-pf). To test against exactly those, in a separate environment so uv.lock is not rewritten:

cp uv.lock "$TEMP/uv.lock"
UV_PROJECT_ENVIRONMENT="$TEMP/venv-server" uv sync --resolution lowest-direct
UV_PROJECT_ENVIRONMENT="$TEMP/venv-server" uv run --no-sync pytest -n auto
cp "$TEMP/uv.lock" uv.lock

GitHub Actions does both on every push (.github/workflows/test.yml).

Release

Bump version in pyproject.toml, run uv lock, and turn the ## Unreleased section of CHANGELOG.md into the version's entry. For each change to a call, give the old and the new call, since the server script is retyped by hand. Commit, then push a tag occu_choice_pf-v<version>; GitHub Actions checks that the tag matches the version, runs the tests, builds and publishes to PyPI (trusted publishing, .github/workflows/publish.yml):

git tag occu_choice_pf-v0.1.0 && git push origin occu_choice_pf-v0.1.0

The same tag runs .github/workflows/publish_1.yml and publish_2.yml, which publish the same code as occu_choice_pf_1 and occu_choice_pf_2. The DST server caches a package when it is installed and won't update that name for 24 hours, so install an exact version under whichever name hasn't been installed in the last 24 hours:

pip install occu-choice-pf==X.Y.Z
pip install occu_choice_pf_1==X.Y.Z
pip install occu_choice_pf_2==X.Y.Z

All three install the import occu_choice_pf, and the most recent install is the one used.

Before a name's first release, register it as a pending trusted publisher on pypi.org (Account settings, Publishing): owner AskerNC, repository occu_choice_pf, environment pypi, and workflow publish.yml for occu-choice-pf, publish_1.yml for occu_choice_pf_1, publish_2.yml for occu_choice_pf_2.

Metadata

Release files for occu_choice_pf_1 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for occu_choice_pf_1 0.10.0
File Size Uploaded Provenance Actions
occu_choice_pf_1-0.10.0.tar.gz 811.4 kB Without provenance Details for occu_choice_pf_1-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for occu_choice_pf_1 0.10.0
File Interpreter ABI Platform Actions
occu_choice_pf_1-0.10.0-py3-none-any.whl Python 3 none any Details for occu_choice_pf_1-0.10.0-py3-none-any.whl

Total release size: 1.6 MB

Release files / occu_choice_pf_1-0.10.0.tar.gz

Download URL occu_choice_pf_1-0.10.0.tar.gz
Size 811.4 kB
Tags Source
SHA-256 checksum
How to use checksums
271828c82bd1d8751d3f3c54a662993697da7f8281b8e610b71324fe1ac6efe0
BLAKE2b-256 checksum
How to use checksums
43941630771416549f9cef7401178e375a2766e920fefaa6cf10ff4541a04d36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / occu_choice_pf_1-0.10.0-py3-none-any.whl

Download URL occu_choice_pf_1-0.10.0-py3-none-any.whl
Size 822.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
896c4951f7825152a97df09a8c6d8f8623474814918ad2e409ca57e2337937ee
BLAKE2b-256 checksum
How to use checksums
bfd96c5230c50b79dd21839a01c0c28fc160e980f239f0f4b623b5d08001e821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for occu_choice_pf_1 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page