-
Notifications
You must be signed in to change notification settings - Fork 2
WIP - FIxing ctpp_censustract_variables #33
base: main
Are you sure you want to change the base?
Conversation
FROM RECODE a, | ||
-- pivot jsonb to columns (key -> field name, value -> field value), | ||
-- this step is needed because not all tracts have all modes of travel | ||
-- NULLs will be filled with 0s and calculated as 0s |
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.
Do we know why certain tracts have missing data? Typically in survey data 0 means people were surveyed and none responded "yes." There are 0 estimates in the raw data, which makes me think that if the missing records were 0, they would have been included. Is it possible to fill NULLS with 0 just for calculating the sum but not when outputting the final table?
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.
The raw data doesn't have all 18 modes for all census tracts. we should probably ask labs for comments, because if we remove the 0 records, it might break the front end.
SELECT | ||
a.geoid, | ||
a.value::numeric::integer as value, | ||
b.moe::numeric::integer as moe, | ||
a.variable | ||
FROM VAL a | ||
JOIN MOE b | ||
ON a.geoid = b.geoid | ||
AND a.variable = b.variable | ||
); |
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.
How about:
SELECT
a.geoid,
CASE
WHEN a.value::numeric = 0 AND b.moe::numeric = 0
THEN NULL
ELSE a.value::numeric::integer
END as value,
CASE
WHEN a.value::numeric = 0 AND b.moe::numeric = 0
THEN NULL
ELSE b.moe::numeric::integer
END as moe,
a.variable
FROM VAL a
JOIN MOE b
ON a.geoid = b.geoid
AND a.variable = b.variable
c451869...3479587
Also it seems like previous python based method has issues in calculating MOEs:
The previous calculation yields 11, which seems to be wrong