Announcement

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

  • how could I redefine label?

    I have to define label
    Code:
     label define defcat2 11 "0-19 (1970-74)" 12 "20-39 (1970-74)" 13 "40-59 (1970-74)" 14 "60+ (1970-74)" 21 "0-19 (1975-79)" 22 "
    > 20-39 (1975-79)" 23 "40-59 (1975-79)" 24 "60+ (1975-79)" 31 "0-19 (1980-84)" 32 "20-39 (1980-84)" 33 "40-59 (1980-84)" 34 "60+
    >  (1980-84)" 41 "0-19 (1985-89)" 42 "20-39 (1985-89)" 43 "40-59 (1985-89)" 44 "60+ (1985-89)" 51 "0-19 (1990-94)" 52 "20-39 (19
    > 90-94)" 53 "40-59 (1990-94)" 54 "60+ (1990-94)" 61 "0-19 (1995-99)" 62 "20-39 (1995-99)" 63 "40-59 (1995-99)" 64 "60+ (1995-99
    > )" 71 "0-19 (2000-04)" 72 "20-39 (2000-04)" 73 "40-59 (2000-04)" 74 "60+ (2000-04)" 81 "0-19 (2005-09)" 82 "20-39 (2005-09)" 8
    > 3 "40-59 (2005-09)" 84 "60+ (2005-09)"
    
    . 
    . 91 "0-19 (2010-13)" 92 "20-39 (2010-13)" 93 "40-59 (2010-13)" 94 "60+ (2010-13)"
    in the last I mistakenly pressed enter before 91. I tried to redo it again but it again shows same error.
    how could i do this?
    Any help?
    thank you

  • #2
    What is the error? Note that the option modify allows definition in stages.

    Comment


    • #3
      There appears to be a pattern in this label definition, and given its length, you might be better off defining it in a loop rather than typing the whole thing out. Apart from the problem you have already encountered hitting enter prematurely, the risk of a typo would be lower.

      Code:
      local agerange1 0-19
      local agerange2 20-39
      local agerange3 40-59
      local agerange4 60+
      
      local era1 1970-74
      local era2 1975-79
      local era3 1980-84
      local era4 1985-89
      local era5 1990-94
      local era6 1995-99
      local era7 2000-04
      local era8 2005-09
      local era9 2010-13
      
      capture label drop defcat2
      
      forvalues a = 1/4 {
          forvalues e = 1/9 {
              label define defcat2 `e'`a' "`agerange`a'' (era`e')", add
          }
      }
      
      label list defcat2
      Note that you could even take this further and define local macros era1 through era8 in a loop instead of writing them out as above:
      Code:
      forvalues e = 1/8 {
          local start = 1965+5*`e'
          local end: display %02.0f  mod(`start' + 4, 100)
          local era`e'  `start'-`end'
      }
      I don't really recommend the latter because it is pretty opaque and you still have to create a separate local macro era9 to cover 2010-13, which does not fit the general pattern.

      Comment

      Working...
      X