Dear all,
I am working in an organization where we do perception survey annually, with over 100 questions every year. What I want to do is to visualize missing values in the data set.
I searched about it a lot and finally I found that we can visualize missing values using missingplot user written command, but this is not what I want to do.
My aim is to compare missing and non-missing values of all variables in a bar graph.
After two days of efforts, I programmed my own command as below:
It solves my problem, but this is a little complicated specially for those who are new to Stata.
Does any one here knows how to plot missing vs non-missing values through a bar chart?, and I would appreciate if anyone could suggest edits on above commands.
Thank you a lot,
Fahim
I am working in an organization where we do perception survey annually, with over 100 questions every year. What I want to do is to visualize missing values in the data set.
I searched about it a lot and finally I found that we can visualize missing values using missingplot user written command, but this is not what I want to do.
My aim is to compare missing and non-missing values of all variables in a bar graph.
After two days of efforts, I programmed my own command as below:
Code:
cap program drop missplot program def missplot syntax [varlist] [if] [, val ] qui snapshot save local snap = `r(snapshot)' cap keep `if' keep `varlist' foreach i of varlist * { cap replace `i' = 0 if `i'!=. cap replace `i' = "0" if `i' != "" cap replace `i' = 1 if `i' ==. cap replace `i' = "1" if `i' == "" cap destring `i', replace } label drop _all qui foreach i of varlist * { sum `i' if `r(mean)' == 0 { drop `i' } } qui des if `r(k)' == 0 { dis as text in red ". No missing values found" snapshot restore `snap' snapshot erase `snap' exit } else { qui ds local missvars = "`r(varlist)'" rename (*) (miss*) gen id = _n qui reshape long miss, i(id) j(vars, "string") lab def miss 1"Missing values" 0"Non-missing values" lab val miss miss dis as text ". Please make sure you have installed tabplot command:" in red " ssc install tabplot" tabplot miss var, showval sep(miss) bar1(bcolor(blue)) bar2(bcolor(red)) xtitle("") ytitle("") subtitle("") } if "`val'" ~= "" { collapse (count) miss if miss==1, by(vars) gsort -miss list , noobs } else { snapshot restore `snap' snapshot erase `snap' exit } end webuse studentsurvey, clear missplot * missplot *, val
Does any one here knows how to plot missing vs non-missing values through a bar chart?, and I would appreciate if anyone could suggest edits on above commands.
Thank you a lot,
Fahim
Comment