Hi
It is not unusual that I have to do a huge amount of exploratory analysis.
So I would like to identify categorical variables in my code (Stata or Mata) in order to set up the correct analysis for the variables.
One way could be to check whether label values is attached to the variable.
But I can't find any examples on that.
So I looked into the code behind codebook and has defined:
But is this the best way? And am I missing something crucial? (I'm fairly new to Stata)
Kind regards/nhb
It is not unusual that I have to do a huge amount of exploratory analysis.
So I would like to identify categorical variables in my code (Stata or Mata) in order to set up the correct analysis for the variables.
One way could be to check whether label values is attached to the variable.
But I can't find any examples on that.
So I looked into the code behind codebook and has defined:
Code:
capture program drop variabel_has_a_label_value program define variabel_has_a_label_value, rclass /*Program returning 1 if argument "variable_name" has a label value in scalar r(has_a_label_value). Otherwise it returns 0. Examples: . variabel_has_a_label_value age . return list scalars: r(has_a_label_value) = 0 . variabel_has_a_label_value sex . return list scalars: r(has_a_label_value) = 1 */ args variabel_name local label_name :value label `variabel_name' if ("`label_name'" != ""){ return scalar has_a_label_value = 1 } else{ return scalar has_a_label_value = 0 } end
Kind regards/nhb
Comment