Announcement

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

  • How to find the key variables in a given dataset?

    Hi there,

    Like the title of the topic mentioned, I met a problem when I'm analyzing a dataset. The dataset does not give me an instruction about which set of variables uniquely define an observation.
    So, are there any functions can automatically report the key variables in a given dataset?

    Thanks!







  • #2
    Code:
    foreach var of varlist * {
        capture isid `var'
        if !_rc {
            di as txt "id variable is: " as result "`var'"
            continue, break
        }
    }
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you, I understand the code, but it could not handle a situation that some key variables are jointly defined. The code could only check if a certain variable is key variable.

      Comment


      • #4
        Originally posted by BICHENG NIU View Post
        Thank you, I understand the code, but it could not handle a situation that some key variables are jointly defined. The code could only check if a certain variable is key variable.
        the combinations quickly get out of hand when you have a compound key defined by 2 or more variables. what can you determine by *looking* at the data? -isid- can be used to verify the variables once you have identified them. Why can't you go back to who produced the data to get any documentation?

        Maarten's approach can be extended to 2 or more variables in a straightforward way:

        Code:
        foreach v1 of varlist * {
          foreach v2 of varlist * {
            if "`v1'" != "`v2'" {
              capture isid `v1' `v2'
              if !_rc {
                di as txt "id variable is: " as result "`v1' `v2'"
                continue, break
              }
            }
          }
        }

        Comment


        • #5
          Originally posted by Leonardo Guizzetti View Post

          the combinations quickly get out of hand when you have a compound key defined by 2 or more variables. what can you determine by *looking* at the data? -isid- can be used to verify the variables once you have identified them. Why can't you go back to who produced the data to get any documentation?

          Maarten's approach can be extended to 2 or more variables in a straightforward way:

          Code:
          foreach v1 of varlist * {
          foreach v2 of varlist * {
          if "`v1'" != "`v2'" {
          capture isid `v1' `v2'
          if !_rc {
          di as txt "id variable is: " as result "`v1' `v2'"
          continue, break
          }
          }
          }
          }
          Thank you very much, very helpful!

          Comment

          Working...
          X