Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shorten variable labels using foreach

    Hello

    I am trying to shorten the labels of the variable in my dataset. Eg:


    storage display value
    variable name type format label variable label
    -----------------------------------------------------------------------------------------------------------------------
    resp_agr_deci~n str1 %9s survey/Group1/resp_agr_decision
    resp_joint_ag~c str1 %9s survey/Group1/resp_joint_agr_decision

    I need to eliminate the first part of the label "survey/Group1/" from each variable label. Is it possible to do it by using substr with foreach command?


    Thank You
    Smriti

  • #2
    Code:
    foreach v of var resp_* {
           local lbl : variable label `v'
           local lbl : subinstr local lbl "survey/Group1/" "", all
           label var `v' "`lbl'"
    }

    Comment

    Working...
    X