Announcement

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

  • findname- display value which text in valulelabel is found.

    Dear All,

    I have been using findname, which is truly excellent bit of code.

    However, i was attempting to search for text within a value label, and then hoping it would tell me what value of the value label it was found at.

    Thinking that it shouldn't be to difficult to add in a bit of code,i had a go, with some success (surprisingly!).

    I amended the following code at line 220. specifically the addition of vvlablist and its accumulation within the if `found' subsection.


    Code:
        qui if `"`vallabeltext'"' != "" {
            local vlist
            local vvlablist
                foreach v of local varlist {
                        local lbl : val label `v'
                if "`lbl'" != "" {
                    levelsof `v' `if', local(levels)
                    foreach l of local levels {
                        local txt : label `lbl' `l', strict
                        mata : find_match(`"`txt'"', `"`vallabeltext'"', `inse', "`found'")
                        if `found' {
                                        local vlist `vlist' `v'
                                        local vvlablist `" `vvlablist' "`v' `l' `txt'" _n"'
                                    continue, break
                                    }
                    }
                        }
                   }
            local varlist `vlist'
         }

    and prior to the termination of the end of the program

    Code:
    
    if `"`vallabeltext'"' != "" {
        di `vvlablist'
            }
    I am sure the is a much prettier way of displaying the results, but i have no idea how to get things nicely lined up in columns.

    I hope someone might find this useful, and i apologize for sullying Nick Cox's code.





  • #2
    findname is from the Stata Journal:

    SJ-15-2 dm0048_3 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q2/15 SJ 15(2):605--606
    updated to be able to find strL variables

    SJ-12-1 dm0048_2 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q1/12 SJ 12(1):167
    correction for handling embedded double quote characters

    SJ-10-4 dm0048_1 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q4/10 SJ 10(4):691
    update for not option

    SJ-10-2 dm0048 . . . . . . . . . . . . . . Speaking Stata: Finding variables
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q2/10 SJ 10(2):281--296
    produces a list of variable names showing which variables
    have specific properties, such as being of string type, or
    having value labels attached, or having a date format

    I can understand why you want this, but I am not going to fold the code back into my version. The purpose of findname is to find variable names; it's my experience that adding functionality to do extra things on the side can obscure the design of a program.

    But I don't feel that my code is being sullied if you adapt it to do something you want. Yet I'd advise changing the name of the revised program to something different, however. The main reason for that is to avoid a clash if you download a revised version of my program (as above).

    Comment


    • #3
      I suspect a little suite of commands would be the best soloution
      findname
      findvarlab
      findvallab

      many thanks

      A




      Comment


      • #4
        What would they do precisely? If you want to find variables with particular text in variable labels, findname does that and lookfor is another possibility.

        I see your problem of finding observations with a particular value label, but note also


        Code:
        sysuse auto 
        l if foreign == "Foreign":`: val label foreign'

        Comment

        Working...
        X