Add your description here
Project description
cdef-cohort-generation
This Python project is part of a research study conducted by the Center for Data og Effektforskning (CDEF) at Mary Elizabeths Hospital, Denmark. The project aims to generate cohorts for an observational study investigating the long-term impact of severe chronic diseases in children on parental income trajectories in Denmark.
The package has been built in such a way that it can be easily extended to include additional registers and data sources. The project is designed to be modular and flexible, allowing for easy integration of new data sources and registers. And also to be easily adaptable to other research projects that require processing and analysis of Danish national registers. But this package focuses on creating the initial cohort/population for the study.
Project Overview
This project is designed to process and analyze data from Danish national registers for an observational study investigating the long-term impact of severe chronic diseases in children on parental income trajectories in Denmark.
The primary objectives of this study are:
- Quantify the difference in total personal income between parents of children with severe chronic diseases and matched controls over a 22-year period (2000-2022).
- Explore how this impact varies across disease severity, geographical location, and parental education levels.
- Examine gender differences in the economic impact of childhood chronic diseases on parents.
- Assess the role of socioeconomic factors in moderating the impact of childhood chronic diseases on parental income trajectories.
Key Features
- Process and combine data from various Danish national registers
- Identify severe chronic diseases using ICD-10 codes
- Generate cohorts for analysis
- Perform longitudinal data analysis
- Apply statistical methods including difference-in-differences analysis and marginal structural models
Installation
This project requires Python 3.12.6 and uses rye
for dependency management.
- Clone the repository
- Install
rye
if you haven't already (see here) - Navigate to the project directory and set up the environment:
rye sync
Usage
To run the main processing script:
python -m cdef_cohort_builder.main
Registers implemented
Registers from Sundhedsdatastyrelsen
- LPR_ADM: Administrative data from hospitals (LPR2)
- LPR_DIAG: Diagnoses from hospitals (LPR2)
- LPR_BES: Outpatient visits from hospitals (LPR2)
- LPR_KONTAKER: Contacts with hospitals (LPR3)
- LPR_DIAGNOSER: Diagnoses from hospitals (LPR3)
Registers from Statistics Denmark
- BEF: Population data
- IND: Income data
- IDAN: IDA employment data
- UDDF: Education data
- AKM: Work classification module
Testing
To run the unit tests:
pytest tests/
Todo
- Make sure LPR2/LPR3 processing is as smooth as possible
- Include mappings for variables + ISCED
- Improve logging and error handling
- Add descriptive plots
- Refactor code for better organization and efficiency
- LPR3 diagnoser / LPR3 kontakter directory names (OBS. convert script)
- Mapping and .env file not included in repo
- SENR not available in early years for AKM
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Contributors
- Tobias Kragholm
Acknowledgments
This project uses data from Danish national registers and is conducted in compliance with Danish data protection regulations.
Documentation
Configuration through environment variables
The project uses environment variables for configuration. The following environment variables are used:
Core functions
process_register_data
The process_register_data
function handles the longitudinal
and join_parents_only
flags in the following ways:
-
Longitudinal flag:
- If
longitudinal
is True:- The function processes each input file separately, adding 'year' and 'month' columns based on the filename.
- It applies column validation and selection to each file individually.
- All processed data frames are concatenated at the end.
- If
longitudinal
is False:- The function reads all input files at once using
pl.scan_parquet(files, ...)
. - Column validation and selection are applied to the entire dataset.
- The function reads all input files at once using
- If
-
Join_parents_only flag:
This flag is used when joining the processed data with the population data (if a population file is provided). It's only relevant for non-longitudinal data processing.
- If
join_parents_only
is True:- The function creates separate datasets for father's and mother's data.
- It prefixes all columns (except the join column) with 'FAR_' for father's data and 'MOR_' for mother's data.
- It then joins these datasets with the population data using 'FAR_ID' and 'MOR_ID' respectively.
- If
join_parents_only
is False:- The function performs a simple join between the processed data and the population data using the specified
join_on
column(s).
- The function performs a simple join between the processed data and the population data using the specified
- If
Key points:
- The
longitudinal
flag primarily affects how the input files are read and processed (individually or all at once). - The
join_parents_only
flag is only relevant when there's a population file to join with, and it determines whether to create separate parent-specific datasets or not. - Both flags work independently of each other, allowing for different combinations of longitudinal/non-longitudinal processing with or without parent-specific joining.
This design allows for flexibility in handling different types of register data and joining requirements.
UDDF
When the longitudinal
flag is set to True and the register being processed is UDDF (Danish Education Register), the processing works as follows:
-
The
process_register_data
function ingeneric.py
is called with thelongitudinal
parameter set to True. -
Instead of reading all files into a single dataframe, each file is processed separately:
- Each .parquet file in the UDDF_FILES directory is read individually.
- Year and month information is extracted from each filename and added as new columns to the dataframe.
- If specified, only the columns listed in
columns_to_keep
are retained.
-
All these individual dataframes are then concatenated into a single large dataframe using
pl.concat(data_frames)
. -
Date columns (HF_VFRA and HF_VTIL) are parsed and converted to the appropriate date format.
-
Special handling for UDDF:
- ISCED (International Standard Classification of Education) data is read and joined with the UDDF data based on the HFAUDD column.
-
The data is then joined with the population file:
- Since
join_parents_only
is True for UDDF, the data is joined twice - once for fathers and once for mothers. - The columns from UDDF are prefixed with "FAR_" for fathers and "MOR_" for mothers, except for the join column (PNR).
- Since
-
The resulting dataframe includes:
- All columns from the population file
- UDDF data for fathers (prefixed with FAR_)
- UDDF data for mothers (prefixed with MOR_)
- Year and month columns indicating when each record was valid
-
Finally, the processed data is written to the output file (UDDF_OUT) in Parquet format.
This longitudinal processing allows for tracking changes in education over time for both parents, with each record associated with a specific year and month.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdef_cohort_builder-0.2.0.tar.gz
.
File metadata
- Download URL: cdef_cohort_builder-0.2.0.tar.gz
- Upload date:
- Size: 185.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d75f1778222a0e180d72a6116c40b3e7b4eed218358d38b5a73e22ccf17c934 |
|
MD5 | e76eb95c36444364154ef4b00cde2b74 |
|
BLAKE2b-256 | 9b337195cf5e0466d8ac5a1f2f9050b9e03f3e8656d1039a94e596bd3762e3fc |
File details
Details for the file cdef_cohort_builder-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: cdef_cohort_builder-0.2.0-py3-none-any.whl
- Upload date:
- Size: 195.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac60ed6f4124e81c78a0d8588b87413359edef64764f746d8740118221e3ff89 |
|
MD5 | 6e2b3e9e43bf383fedd5ebde51bd95ce |
|
BLAKE2b-256 | 482fd075aacb2c5e8055eb9a65dcf171a3543947b7f067f0c53f8ae714fd8d4a |