Announcement

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

  • findname: Find variables based on all words

    Hi,
    I wanted to identify all variables whose variable labels has all the specific keywords. For example,
    Code:
    Code:
    sysuse auto
    Code:
    findname, varlabel(*in* *cu*)
    The above code lists 4 varibales viz. headroom trunk length displacement which have either of cu and in words in the variable labels. What I want STATA to do is list only displacement variable becaus only this variable has both the words cu and in in its variable label. Is there a way to do this?

    Also, is there a way to match exact string? For example, I want to identify variables which have Rejection string in their variable labels, excluding those which have Rejections string in their varlabels.

    Can -findname- or -ds- commands be used to perform the above two task? If not then what is the solution?

    Thank you.
    Amit

  • #2
    One way

    Code:
    ds , has(varlabel *in*)
    local varlist_1 `r(varlist)'
    ds , has(varlabel *cu*)
    local varlist_2 `r(varlist)'
    
    local both : list varlist_1 & varlist_2
    display "`both'"

    Comment


    • #3
      Thank you Daniel. This works exactly the way I want. But your code still does not solve problem of exact matching. Is there a way?

      Comment


      • #4
        Another method should be

        Code:
         
         ds , has(varlabel *in*) ds `r(varlist)' , has(varlabel *cu*)
        The other problem is the difference between two sets, which I think needs to be done one step at a time.

        Comment


        • #5
          I am not sure I fully understand the problem; partly because there is no data example.

          Code:
          ds , has(varlabel "Rejection *")
          (note quotation marks and spaces) should match variable labels starting with rejection followed by a space and possibly other characters. If you need something else, please provide an example.

          Comment


          • #6
            Thank you Nick and Daniel. Much helpful!

            Comment

            Working...
            X