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

  • Defining variables in a loop

    Hello All,
    I have a long list of variables that all need to be defined in the same way.

    I wrote the following which simply returns the error "invalid syntax".
    The code works when I run with the lab val but without the lab def, suggesting a problem with the label define portion.

    Advice please!

    local varname "esttype_br_rural esttype_br_total esttype_br_urban [ of varnames.]"
    local a=wordcount("`varname'")

    forval i=1/`a'{
    local name=word("`varname'", `i')
    lab val `varname' `varname'_lab
    lab def `varname'_lab ///
    1 "Annual estimate" ///
    3 "Three year moving average" ///
    5 "Five year estimate" ///
    10 "Ten year census"
    Last edited by Anne Morse; 24 Jun 2019, 12:01. Reason: Nevermind, fixed it!

  • #2
    Never mind, fixed it!