Skip to content

Instantly share code, notes, and snippets.

@pushkarnimkar
Created August 13, 2021 06:25
Show Gist options
  • Save pushkarnimkar/fe3f7217b45626d4e68fb999d7502b8a to your computer and use it in GitHub Desktop.
Save pushkarnimkar/fe3f7217b45626d4e68fb999d7502b8a to your computer and use it in GitHub Desktop.
Query for finding the HRH raw numbers (1983, 2000, 2011) from the NSS data
create temp function occupation_nco_1968(nco string)
returns string as (
case
when nco = '085' then 'aux_nurse'
when nco = '084' then 'nurse'
when nco = '067' then 'pharmacist'
when nco = '070' then 'allopathic'
when nco = '074' then 'dentist'
when nco = '071' then 'ayush'
when nco = '072' then 'ayush'
when nco = '073' then 'ayush'
else 'other'
end
);
with
workers_38 as (
select
occupation_nco_1968(B42_q14) as occupation,
Hhold_key as hhid,
Wgt4_pooled as weight
from
`asar-287123.nss.nss_38_block_42`
),
households_38 as (
select
hhid,
occupation,
count(occupation) as count_,
any_value(weight) as weight
from
workers_38
where
occupation != 'other'
group by
hhid,
occupation
),
estimates_38 as (
select
occupation,
sum(count_ * weight) as population_
from
households_38
group by
occupation
),
workers_55 as (
select
occupation_nco_1968(B51_q6) as occupation,
Key_hhold as hhid,
Wgt_SR_comb as weight
from
`asar-287123.nss.nss_55_block_511`
),
households_55 as (
select
hhid,
occupation,
count(occupation) as count_,
any_value(weight) as weight
from
workers_55
where
occupation != 'other'
group by
hhid,
occupation
),
estimates_55 as (
select
occupation,
sum(count_ * weight) as population_
from
households_55
group by
occupation
)
select * from estimates_55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment