I want to list a variable's name, label, as well as all values and value labels on one line, for each variable in the dataset.
For example:
foreign, Car type, 0 Domestic 1 Foreign
I managed to write some code to do this, but it only shows value labels that are used in the dataset:
sysuse auto, clear
foreach var of varlist * {
local _check: val l `var'
if `"`_check'"' != "" {
quietly fre `var'
di "`var'" char(44) `"`: var label `var' '"' char(44) as result r(lab_valid)
continue
}
else{
di "`var'" char(44) `"`: var label `var' '"'
continue
}
}
Here the community-contributed command fre
would only include 0 Domestic
, if the data did not include 1 Foreign
.
There are easier ways to show value labels, but all show them on different lines.