Announcement

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

  • Number of variables with the same prefix

    Hi,

    I am using Stata 13 and would like to count the number of variables in a dataset that start with the same prefix.

    Any assistance will be greatly appreciated.

  • #2
    Hi,

    I have found a solution. This should work.

    local y=0
    foreach var of varlist savingpurpose* {
    local ++y
    }
    di "`y'"

    Thanks all who have made efforts.

    Comment


    • #3
      Creative solution. Here is another

      Code:
      unab myvars : savingpurpose*
      local count : word count `myvars'
      display "There are " `count' " variables starting with savingpurpose*"
      Best
      Daniel

      Comment


      • #4
        Thanks Daniel. Yours too is a great one. Great thanks.

        Comment

        Working...
        X