-
Notifications
You must be signed in to change notification settings - Fork 1
Add cleaning script for the generated health module (SF-12) #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hmgaudecker
wants to merge
6
commits into
main
Choose a base branch
from
feat/health-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+698
−10
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39f4390
Add cleaning script for the generated health module (SF-12)
hmgaudecker 39d9aea
Merge branch 'main' into feat/health-module
hmgaudecker 13e6b7e
Clean float SF-12/BMI health columns with float_to_float
hmgaudecker 43c27d0
Merge remote-tracking branch 'origin/main' into feat/health-module
hmgaudecker b363db2
Merge branch 'feat/health-module' of github.com:ttsim-dev/soep-prepar…
hmgaudecker 4721cbf
update metadata mapping
hmgaudecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """Clean and convert SOEP health variables to appropriate data types.""" | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from soep_preparation.utilities.data_manipulator import ( | ||
| apply_smallest_int_dtype, | ||
| create_dummy, | ||
| float_to_float, | ||
| ) | ||
|
|
||
|
|
||
| def clean(raw_data: pd.DataFrame) -> pd.DataFrame: | ||
| """Create cleaned variables from the health module. | ||
|
|
||
| The health module is a generated person-year dataset with health | ||
| indicators collected in a two-year replication cycle since 2002. Its | ||
| centerpiece is the SOEP version of the SF-12v2: eight norm-based | ||
| subscales plus the physical (PCS) and mental (MCS) component summary | ||
| scales, all standardized to mean 50 and standard deviation 10 in the | ||
| SOEP 2004 population, with higher values representing better | ||
| health-related quality of life. | ||
|
|
||
| Args: | ||
| raw_data: The raw health data. | ||
|
|
||
| Returns: | ||
| The processed health data. | ||
| """ | ||
| out = pd.DataFrame() | ||
|
|
||
| out["p_id"] = apply_smallest_int_dtype(raw_data["pid"]) | ||
| out["hh_id_original"] = apply_smallest_int_dtype(raw_data["cid"]) | ||
| out["survey_year"] = apply_smallest_int_dtype(raw_data["syear"]) | ||
|
|
||
| # Component summary scales. The SF-12 scores and BMI arrive as floats with | ||
| # SOEP missing codes encoded as negative values. | ||
| out["sf12_pcs"] = float_to_float(raw_data["pcs"], code_negative_values_as_na=True) | ||
| out["sf12_mcs"] = float_to_float(raw_data["mcs"], code_negative_values_as_na=True) | ||
|
|
||
| # The eight norm-based subscales underlying the summary scales. | ||
| out["sf12_physical_functioning_nbs"] = float_to_float( | ||
| raw_data["pf_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_role_physical_nbs"] = float_to_float( | ||
| raw_data["rp_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_bodily_pain_nbs"] = float_to_float( | ||
| raw_data["bp_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_general_health_nbs"] = float_to_float( | ||
| raw_data["gh_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_vitality_nbs"] = float_to_float( | ||
| raw_data["vt_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_social_functioning_nbs"] = float_to_float( | ||
| raw_data["sf_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_role_emotional_nbs"] = float_to_float( | ||
| raw_data["re_nbs"], code_negative_values_as_na=True | ||
| ) | ||
| out["sf12_mental_health_nbs"] = float_to_float( | ||
| raw_data["mh_nbs"], code_negative_values_as_na=True | ||
| ) | ||
|
|
||
| # Whether all twelve items needed for the SF-12 scoring are complete. | ||
| out["sf12_valid"] = create_dummy( | ||
| series=raw_data["valid"], | ||
| value_for_comparison="[1] Yes", | ||
| comparison_type="equal", | ||
| ) | ||
|
|
||
| out["bmi_health"] = float_to_float(raw_data["bmi"], code_negative_values_as_na=True) | ||
|
|
||
| return out | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what
sf12,mcs,nbs,pcsactually mean, but keep it if it's jargon.