i am trying to save the value labels of a variable to write them into a file together with their values afterwards. However, i cannot figure out how to save the labels in a table in order to call them one by one.
I am saving the variable values with levelsof:
Code:
levelsof state, missing local(values)
Code:
0 1 2 3 5 6 7 8 9 12 13 14 15 16
Code:
elabel list (state) local valueLabel r(labels)
Code:
"Berlin" "Schleswig-Hols." "Hamburg/Bremen" "Lower Saxony" "N-Rhein-Westfa." "Hessen" "R-Pfalz,Saarl." "Baden-Wuerttemb." "Bavaria" "Mecklenburg-V." "Brandenburg" "Saxony-Anhalt" "Thueringen" "Saxony" "Refusal" "Does not apply" "Inconsistent"
I am trying to write the values together with their matching value labels into a file as such:
Code:
file open handle using file.csv, write replace
tokenize `valueLabel'
local i = 1
foreach v of local values {
local curr_valueLabel : di word(`valueLabel', `i')
file write handle "`v'" _tab
file write handle "`curr_valueLabel'" _n
local i = `i' + 1
}
file close handleIs there any way to save the value labels in a matrix like
Code:
levelsof state, matrow(matname)
Any help would be greatly appreciated!
0 Response to Create a table from value labels
Post a Comment