I have built a readable codebook using the describe command as follows:
Code:
use "$mastData/Dataset1.dta", clear describe, replace save "$mastData/Codebook.dta", replace
I can write something to label the variables and labels in a new file (Dataset2.dta) with those of the original file (Dataset1.dta), but I don't think it's the most efficient way & want to know if I'm missing an easier way/command.
Code:
* save val and var labels
use "$mastData/Dataset1.dta", clear
label save using "$mastData/_vallabels", replace
describe, replace
save "$mastData/Codebook.dta", replace
* write label do file
use "$mastData/Codebook.dta", clear
// dofile
tempname fh
local N = c(N)
// create a new do-file
file open `fh' using "$mastData/_labels.do", write replace
forvalues i = 1/`N' {
// variable labels
file write `fh' "cap label variable `= name[`i']' "
file write `fh' `""`= varlab[`i']'""' _newline
// value labels
file write `fh' "cap label values `= name[`i']' "
file write `fh' `""`= vallab[`i']'""' _newline
}
file close `fh'
* label new dataset
use "$mastData/Dataset2.dta", clear
do "$mastData/_vallabels"
do "$mastData/_labels.do"
0 Response to Using a codebook generated by "describe, replace" to label another dataset
Post a Comment