Last active
October 8, 2015 04:20
-
-
Save markdanese/67b5dd12865ff53a1597 to your computer and use it in GitHub Desktop.
script to read in Medicare Part D Prescriber data for 2013
This file contains 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
# ---------- US Part D Drug prices 2013 ---------- # | |
library(data.table) | |
library(magrittr) | |
# data from http://download.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/Medicare-Provider-Charge-Data/Downloads/PartD_Prescriber_PUF_NPI_DRUG_13.zip | |
# 500 MB ZIP file download, 2.9 GB uncompressed | |
pde <- "http://download.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/Medicare-Provider-Charge-Data/Downloads/PartD_Prescriber_PUF_NPI_DRUG_13.zip" | |
tf <- tempfile() | |
download.file(pde, tf) | |
x <- unzip(tf, exdir = tempdir()) | |
z <- fread(x[2], verbose = TRUE) | |
unlink(x) # removes the tempfiles | |
rm(x) | |
setkey(z, "GENERIC_NAME") | |
partd <- | |
z[, .( | |
claims = sum(TOTAL_CLAIM_COUNT, na.rm = TRUE), | |
days_supp = sum(TOTAL_DAY_SUPPLY, na.rm = TRUE), | |
tot_cost = sum(TOTAL_DRUG_COST, na.rm = TRUE) | |
), | |
by = .(drug = GENERIC_NAME)] %>% | |
.[, drug := tolower(drug)] %>% | |
.[, cost_per_day := round(tot_cost / days_supp, 2)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment