Announcement

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

  • How to return a list of variables with no value label or varlabel?

    I have a dataset of thousands of variables, and I want to find the names of those without a value lable and without a varlabel. Any idea how?

  • #2
    See

    Code:
    help ds
    For you purposes

    Code:
    ds , not(varlabel)
    local no_varlabel `r(varlist)'
    ds , not(vallabel)
    local no_vallabel `r(varlist)'
    local varlist : list no_varlabel & no_vallabel
    should do.

    A nice alternative is findname (SJ).

    Code:
    findname , varlabel vallabel not
    local varlist `r(varlist)'
    Best
    Daniel

    Comment


    • #3
      Daniel, Thanks. A couple followups

      1) Neither of these commands list the entire variable name (e.g. instead of "this_variablaname_is_long", it returns "this_var~ng"). How do I get the full variable name?

      2) Just for my general knowledge, how do I know if things are stored in macros like `r(varlist)'? I thought -return list- should show it, but it doesn't in this case

      Comment


      • #4
        1) Neither of these commands list the entire variable name (e.g. instead of "this_variablaname_is_long", it returns "this_var~ng"). How do I get the full variable name?
        You could

        Code:
        foreach var of local varlist {
            display "`var'"
        }
        Why would you want to see the full names?

        2) Just for my general knowledge, how do I know if things are stored in macros like `r(varlist)'? I thought -return list- should show it, but it doesn't in this case

        What do you mean when you say that

        Code:
        return list
        does not show this? Can you show an example?

        Edit: Note that when ds (or findname) do not find any variables that match the search patter, nothing is returned in r().

        The returned results are typically documented in the respective help file. For findname the information is in the Description section not listed at the end of the help file as would be usual.

        Best
        Daniel
        Last edited by daniel klein; 30 May 2018, 09:35.

        Comment


        • #5
          Daniel answered most of Tommie's questions very nicely. Note further that both ds and findname have a documented varwidth() option which can be used to increase the space devoted to showing variable names.

          Comment

          Working...
          X