isknown - Stata module by Sergiy Radyakin

Description

isknown checks whether values of one variable (probevar) occur among the values of another variable (referencevar). It works with both numeric and string variables, but both variables must be of the same type. The result is placed into a new zero-one variable, with values 1 corresponding to known values of probevar and 0 to unknown values.

Installation

To install isknown copy the file isknown.ado to your PLUS or PERSONAL directory. See adopath.

Usage

The following is the basic syntax for isknown:

  isknown referencevar probevar, generate(resultvar)

The variable resultvar will be created, and both referencevar and probevar must exist and be of the same type (either both numeric or both strings).

An extended syntax is available, where the user can specify a value label:

  isknown referencevar probevar, generate(resultvar) ///
    label("lresult" "label if unknown" "label if known")

A shorter version is also available:

  isknown referencevar probevar, generate(resultvar) label(lresult)

lresult is the name of the value label dictionary attached to the resulting variable. Usually the same name as resultvar is sufficient, but one can also prepend it with l or l_.

Examples

Example 1

This example follows the original request at Statalist forum.

clear all
input id var1 var2
	1 3 2
	1 4 5
	2 6 4
	2 2 1
	2 4 1
	3 4 5
	4 9 3
end

isknown var1 var2, generate(var3) label(isknown)
list

The result is:


     +----------------------------+
     | id   var1   var2      var3 |
     |----------------------------|
  1. |  1      3      2     known |
  2. |  1      4      5   unknown |
  3. |  2      6      4     known |
  4. |  2      2      1   unknown |
  5. |  2      4      1   unknown |
     |----------------------------|
  6. |  3      4      5   unknown |
  7. |  4      9      3     known |
     +----------------------------+

Example 2

The second example demonstrates the program working with strings.

clear all
input byte id str10 var1 str10 var2
	1  "John"       "Jack"
	2  "Jill"       "Mary"
	3  "Catherine"  "Kristina"
	4  "Adam"       "Bob"
	5  "Charlie"    "Danny"
	6  "Bob"        "Danny"
	7  "Mary"       "Catherine"
	8  "Robert"     "Patrick"
	9  "Alex"       "Alex"
	10 "Heather"    "John"
end

isknown var1 var2, generate(var3) label("lresult" "not mentioned" "mentioned")
list

The result is:


     +--------------------------------------------+
     | id        var1        var2            var3 |
     |--------------------------------------------|
  1. |  1        John        Jack   not mentioned |
  2. |  2        Jill        Mary       mentioned |
  3. |  3   Catherine    Kristina   not mentioned |
  4. |  4        Adam         Bob       mentioned |
  5. |  5     Charlie       Danny   not mentioned |
     |--------------------------------------------|
  6. |  6         Bob       Danny   not mentioned |
  7. |  7        Mary   Catherine       mentioned |
  8. |  8      Robert     Patrick   not mentioned |
  9. |  9        Alex        Alex       mentioned |
 10. | 10     Heather        John       mentioned |
     +--------------------------------------------+

Author and support

isknown was written by Sergiy Radyakin. To contact the author start a topic at the StataList forum.