Published
Edited
Dec 1, 2020
Insert cell
md`# parse and create stata \`replace\` statements for npi taxonomy codes

After getting variable names and labels from \`describe, replace\` and creating indicator and grouping variables using simple string matching.`
Insert cell
d3
.groups(data, d => d.taxonomy_value)
.sort((a, b) => d3.descending(a[0], b[0]))
.map(function(d) {
const codeName = d[1].find(e => e.taxonomy_code).name;
const switchName = d[1].find(e => e.taxonomy_switch).name;
return `replace primary_code = ${codeName} if ${switchName} == 'Y'`;
})
.join("\n")
Insert cell
data = FileAttachment("taxonomy_variables_list.csv").csv({ typed: true })
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more