Announcement

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

  • Findname problem for Likert variables

    I've been trying to use findname to get a list of Likert variables where the values range from 1 to 7. However, it is not finding a set of variables that have such value ranges. Here's an example of the code where it fails to find inc1w1. Is there a reason for this?


    Code:
    . . findname, all((@ >= 0 & @ <= 7))
    racecnt       taid7         taid18        tmmxhoneshex  tmmiagreehex  tmmxzhones~x  tmmiinc       tmjust        tmsdpj
    race_unknown  taid8         taid19        tmsdhoneshex  tmmxagreehex  tmsdzhones~x  tmmxinc       tmmijust      tminfj
    racea         taid9         taid20        tmemotihex    tmsdagreehex  tmmxzemoti~x  tmsdinc       tmmxjust      tmmiinfj
    genderb       taid10        taid21        tmmiemotihex  tmconschex    tmsdzemoti~x  tmincsh       tmsdjust      tmmxinfj
    wavetotal     taid11        taid22        tmmxemotihex  tmmiconschex  tmsdzextra~x  tmmiincsh     tmdj          tmsdinfj
    taid1         taid12        taid23        tmsdemotihex  tmmxconschex  tmmxzagree~x  tmmxincsh     tmmidj        tmintj
    taid2         taid13        taid24        tmextrahex    tmsdconschex  tmsdzagree~x  tmsdincsh     tmmxdj        tmmiintj
    taid3         taid14        taid25        tmmiextrahex  tmopennhex    tmsdzconsc~x  tmps          tmsddj        tmmxintj
    taid4         taid15        taid26        tmmxextrahex  tmmiopennhex  tmmxzopenn~x  tmmips        tmpj          tmsdintj
    taid5         taid16        tmhoneshex    tmsdextrahex  tmmxopennhex  tmsdzopenn~x  tmmxps        tmmipj
    taid6         taid17        tmmihoneshex  tmagreehex    tmsdopennhex  tminc         tmsdps        tmmxpj
    
    . 
    . 
    end of do-file
    
    .  tab inc1w1, nolab
    
    In the past |
    seven days, |
    my team has |
       given me |
    the feeling |
         that I |
        belong. |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |          3        1.32        1.32
              3 |          5        2.19        3.51
              4 |          1        0.44        3.95
              5 |         10        4.39        8.33
              6 |         80       35.09       43.42
              7 |        129       56.58      100.00
    ------------+-----------------------------------
          Total |        228      100.00

  • #2
    My guess is that inc1w1 may have a missing value. Because missing value is >7, the variable did not get selected.

    Comment


    • #3
      That's my guess too. (findname is from the Stata Journal.)

      You can add
      | missing(@) to the condition.

      Comment


      • #4
        OK that worked. I didn't know that missing values are >7. On a related note is there a way to find variables that have names like inc1w1 inc2w1 inc1w2 etc, but not exclude variables where the fourth or sixth character is a character. So I'd need to exclude incxwp for instance. In a regular expression this would be something like inc[0-9]w[0-9[

        Comment


        • #5
          This will allow you scan for patterns using regular expressions.

          Code:
          qui ds
          local vars `r(varlist)'
          
          local match_vars
          forval i = 1/`: word count `vars'' {
              local v : word `i' of `vars'
              if ustrregexm("`v'", "inc[0-9]w[0-9]", .) {
                local match_vars `match_vars' `v'
            }
          }

          Comment


          • #6
            Variable names can only contain a limited set of characters where the relevant distinction is between numeric/digits and non-numeric characters. rename matches digits in variable names:

            Code:
            rename (inc#w#) (_=) , dryrun r
            return list

            Comment

            Working...
            X