Announcement

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

  • #16
    Thanks for all. I admit a preference for dealing in macros over altering data files when possible, making your last example closer to ideal (no criticism expressed or implied).

    Comment


    • #17
      Coming back to the original problem:

      Code:
      levelsof year, local(yrs)
      foreach y of local yrs {    
          levelsof tfr if year==`y', local(t)      
          local yrlab `yrlab' "`y', `y' <TFR=`t'>"
      }
      Given a one-to-one correspondence between years and tfr, this is another way to do it:

      Code:
      su year, meanonly
      
      forval y = `r(min)'/`r(max)' {
          su tfr if year == `y', meanonly
          if r(N) > 0 {
               local yrlab  "`y', `y' <TFR=`r(min)'>"
          }
      }
      If there are no gaps in the sequence of years, the code can be simplified.
      Last edited by Nick Cox; 17 Oct 2014, 03:39.

      Comment

      Working...
      X