Hi,

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)
Which gives me:

Code:
0 1 2 3 5 6 7 8 9 12 13 14 15 16
In order to obtain the value labels of the variable state, I am using the elabel package from Daniel Klein:

Code:
elabel list (state)
local valueLabel r(labels)
di `valueLabel' will put out:
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"
However, the labels stored in `valueLabel' are one big string and cannot be targeted one by one.

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 handle
I tried "tokenize" on the macro `valueLabel' but this will break up labels that consists of multiple words like "Lower Saxony".

Is there any way to save the value labels in a matrix like
Code:
levelsof state, matrow(matname)
would do for the values?

Any help would be greatly appreciated!