-
Notifications
You must be signed in to change notification settings - Fork 0
[PULL REQUEST] Households by Workers #278
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
Merged
+790
−46
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0b7cb73
#247 - hh by workers tract controls
86a604e
#247 - hh by workers mgra controls
d3e8ec2
#247 - hh by workers input and validation
a1faaac
#247 - hh by workers create, validate, and insert
015a545
#278 - CoPilot PR Feedback
9ae9e95
#278 - correct implied hh sizes
9f8000a
#278 - clean up hh workers hh size adjustment method
ba21fd6
Potential fix for pull request finding 'Unreachable code'
GregorSchroeder 6a6cfd0
#278 - Code quality fix
772413b
#278 - pr feedback restrict 18+ to household population
7f38083
#278 - wiki update
0de17c2
Revert "#278 - wiki update"
e959239
#278 - pr feedback wiki update
a7596e3
#278 - add qc checks
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,39 @@ | ||
| -- SQL script to check that households by workers do not exceed households by size | ||
| DECLARE @run_id INTEGER = :run_id; | ||
|
|
||
|
|
||
| -- Check hard constraint of household size is not violated | ||
| WITH [Household Size] AS ( | ||
| SELECT | ||
| [year], | ||
| [mgra], | ||
| SUM(CASE WHEN [metric] != 'Household Size - 1' THEN [value] ELSE 0 END) AS [2+ size], -- 2+ household size | ||
| SUM(CASE WHEN [metric] NOT IN ('Household Size - 1','Household Size - 2') THEN [value] ELSE 0 END) AS [3+ size] -- 3+ household size | ||
| FROM [outputs].[hh_characteristics] | ||
| WHERE [run_id] = @run_id AND [metric] LIKE 'Household Size%' | ||
| GROUP BY [year], [mgra] | ||
| ), | ||
| [Household Workers] AS ( | ||
| SELECT | ||
| [year], | ||
| [mgra], | ||
| SUM(CASE WHEN [metric] = 'Household Workers - 2' THEN [value] ELSE 0 END) AS [2 workers], | ||
| SUM(CASE WHEN [metric] = 'Household Workers - 3+' THEN [value] ELSE 0 END) AS [3+ workers] | ||
| FROM [outputs].[hh_characteristics] | ||
| WHERE [run_id] = @run_id AND [metric] LIKE 'Household Workers%' | ||
| GROUP BY [year], [mgra] | ||
| ) | ||
| SELECT | ||
| [Household Size].[year], | ||
| [Household Size].[mgra], | ||
| [Household Size].[2+ size], | ||
| [Household Size].[3+ size], | ||
| [Household Workers].[2 workers], | ||
| [Household Workers].[3+ workers] | ||
| FROM [Household Size] | ||
| INNER JOIN [Household Workers] | ||
| ON [Household Size].[year] = [Household Workers].[year] | ||
| AND [Household Size].[mgra] = [Household Workers].[mgra] | ||
| WHERE | ||
| [Household Size].[2+ size] < [Household Workers].[2 workers] | ||
| OR [Household Size].[3+ size] < [Household Workers].[3+ workers] |
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,47 @@ | ||
| -- SQL script to check that implied workers do not exceed persons aged 18+ | ||
| DECLARE @run_id INTEGER = :run_id; | ||
|
|
||
|
|
||
| -- Check soft constraint of persons aged 18+ | ||
| WITH [Household Size] AS ( | ||
| SELECT | ||
| [year], | ||
| [mgra], | ||
| SUM( | ||
| CASE | ||
| WHEN [metric] = 'Household Workers - 1' THEN [value] | ||
| WHEN [metric] = 'Household Workers - 2' THEN [value]*2 | ||
| WHEN [metric] = 'Household Workers - 3+' THEN [value]*3 | ||
| ELSE 0 | ||
| END | ||
| ) AS [min_workers] | ||
| FROM [outputs].[hh_characteristics] | ||
| WHERE [run_id] = @run_id AND [metric] LIKE 'Household Workers%' | ||
| GROUP BY [year], [mgra] | ||
| ), | ||
| [Population Aged 18+] AS ( | ||
| SELECT | ||
| [year], | ||
| [mgra], | ||
| SUM([value]) AS [persons_18plus] | ||
| FROM [outputs].[ase] | ||
| WHERE | ||
| [run_id] = @run_id | ||
| AND [age_group] NOT IN ( | ||
| 'Under 5', | ||
| '5 to 9', | ||
| '10 to 14', | ||
| '15 to 17' | ||
| ) | ||
| GROUP BY [year], [mgra] | ||
| ) | ||
| SELECT | ||
| [Household Size].[year], | ||
| [Household Size].[mgra], | ||
| [Household Size].[min_workers], | ||
| ISNULL([Population Aged 18+].[persons_18plus], 0) AS [persons_18plus] | ||
| FROM [Household Size] | ||
| LEFT OUTER JOIN [Population Aged 18+] | ||
| ON [Household Size].[year] = [Population Aged 18+].[year] | ||
| AND [Household Size].[mgra] = [Population Aged 18+].[mgra] | ||
| WHERE [min_workers] > ISNULL([Population Aged 18+].[persons_18plus], 0); |
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
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
47 changes: 47 additions & 0 deletions
47
sql/hh_characteristics/get_mgra_controls_hh_by_workers_18plus.sql
|
GregorSchroeder marked this conversation as resolved.
|
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,47 @@ | ||
| /* | ||
| Get MGRA controls for persons aged 18+ used in households by number of workers. | ||
| This data is pulled from previously run modules. | ||
|
|
||
| It would be preferable to use 16+ as that is the age of eligibility for labor | ||
| force participation in the ACS but the Estimates Program uses 15 to 17 as an | ||
| age category so there is not an easy way to select only 16+. | ||
|
|
||
| Two input parameters are used | ||
| run_id - the run identifier for this run | ||
| year - the year parameter grabs the year of data to use | ||
| */ | ||
|
|
||
| -- Initialize parameters | ||
| DECLARE @run_id integer = :run_id; | ||
| DECLARE @year integer = :year; | ||
|
|
||
| -- Get population aged 18+ | ||
| WITH [ase_data] AS ( | ||
| SELECT | ||
| [mgra], | ||
| SUM([value]) AS [value] | ||
| FROM [outputs].[ase] | ||
| WHERE | ||
| [run_id] = @run_id | ||
| AND [year] = @year | ||
| AND [pop_type] = 'Household Population' | ||
| AND [age_group] NOT IN ( | ||
| 'Under 5', | ||
| '5 to 9', | ||
| '10 to 14', | ||
| '15 to 17' | ||
| ) | ||
| GROUP BY [mgra] | ||
| ) | ||
| -- Ensure all MGRAs are included | ||
| SELECT | ||
| @run_id AS [run_id], | ||
| @year AS [year], | ||
| [mgra].[mgra], | ||
| ISNULL([value], 0) AS [persons_18plus] | ||
| FROM [inputs].[mgra] | ||
| LEFT OUTER JOIN [ase_data] | ||
| ON [mgra].[mgra] = [ase_data].[mgra] | ||
| WHERE | ||
| [mgra].[run_id] = @run_id | ||
| ORDER BY [mgra].[mgra] |
46 changes: 46 additions & 0 deletions
46
sql/hh_characteristics/get_mgra_controls_hh_by_workers_hhs.sql
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,46 @@ | ||
| /* | ||
| Get MGRA controls for households by size used in households by number of workers. | ||
| This data is pulled from previously run portions of this module. | ||
|
|
||
| Since households by workers only contains (0,1,2,3+) categories, the household | ||
| size categories are collapsed to (2+,3+) to match the minimum implied household | ||
| sizes from the households by workers categories (e.g. 0 and 1 worker households | ||
| can be any size 1+, a 2 worker household must be at least size 2, and a three | ||
| worker household must be at least size 3). | ||
|
|
||
| Two input parameters are used | ||
| run_id - the run identifier for this run | ||
| year - the year parameter grabs the year of data to use | ||
| */ | ||
|
|
||
| -- Initialize parameters | ||
| DECLARE @run_id integer = :run_id; | ||
| DECLARE @year integer = :year; | ||
|
|
||
| -- Get households by size | ||
| SELECT | ||
| @run_id AS [run_id], | ||
| @year AS [year], | ||
| [mgra], | ||
| SUM( | ||
| CASE | ||
| WHEN [metric] != 'Household Size - 1' THEN [value] | ||
| ELSE 0 | ||
| END | ||
| ) AS [2], -- 2+ household size | ||
| SUM( | ||
| CASE | ||
| WHEN [metric] NOT IN ( | ||
| 'Household Size - 1', | ||
| 'Household Size - 2' | ||
| ) THEN [value] | ||
| ELSE 0 | ||
| END | ||
| ) AS [3] -- 3+ household size | ||
| FROM [outputs].[hh_characteristics] | ||
| WHERE | ||
| [run_id] = @run_id | ||
| AND [year] = @year | ||
| AND [metric] LIKE 'Household Size%' | ||
| GROUP BY [mgra] | ||
| ORDER BY [mgra] |
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.
Uh oh!
There was an error while loading. Please reload this page.