Skip to content

Instantly share code, notes, and snippets.

@isaacgeng
isaacgeng / HW.ipynb
Last active January 26, 2019 09:42
HW.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// label vars using 1st row, then drop 1st row
foreach var of varlist * {
label variable `var' "`=`var'[1]'"
replace `var'="" if _n==1
}
drop in 1
// wrap into a program
cap program drop mapvalues
program define mapvalues
syntax varlist, a(string) b(string)
@isaacgeng
isaacgeng / label_dates.do
Last active January 30, 2022 04:15
code snippet to gen label weeks to let esttab know which is which
// label all weeks so that we know which week
// 2020
local clearall
cap label drop week_lab20
cap label drop week_lab21
local i1 = tw(2020w1)
local i2 = tw(2020w52)
local j = 1
forvalues i = `i1'/`i2'{
label define week_lab `i' "20week`j'", add
sysuse bpwide, clear
bys agegrp : egen bldps_m = mean(bp_after)
keep agegrp bldps_m
duplicates drop
rename (bldps_m agegrp) (y x)
sum y
local plot_min = r(min)*0.97
tw (sc y x) ///
@isaacgeng
isaacgeng / CustomBlabel.do
Last active February 25, 2024 03:28
Bar plot with custom bar label
// see https://www.statalist.org/forums/forum/general-stata-discussion/general/33124-adding-other-data-as-a-label-to-bar-graph
sysuse census, clear
collapse (sum) pop pop5_17, by(region)
generate pr_5_17 = round(pop5_17/pop, 0.01)*100
replace pop = pop/1000000
rename pop pop_millions
graph bar (asis) pop_millions, over(region) ytitle("Population (In Millions)") blabel(bar)