Announcement

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

  • Does this situation require a reshape long, or something different?

    Dear Statalisters,

    I would like to efficiently convert the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str20 name byte(knowsA knowsB freqA freqB lengthA lengthB)
    "A" 0 1 . 2 . 10
    "B" 1 0 4 . 9 .
    end
    into this format:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str20(source target) byte(knows freq length)
    "A" "A" 0 . .
    "A" "B" 1 2 10
    "B" "A" 1 4 9
    "B" "B" 0 . .
    end
    To give more context, in the first example, the variable "name" denotes the name of an individual. The variables "knowsA" and "knowsB" are binary, equal to 1 if the individual in the observation knows the individual in the variable "name". We assume that an individual will always answer no to their own variable, so "knowsA" will be equal to 0 for individual A, and the same goes for "knowsB" with individual B. "freqA" and "lengthA" denote the frequency and length of the relationship with A in the case that "knowsA" is equal to 1, and similarly with "freqB" and "lengthB".

    This way of formatting variables is not satisfactory because, as you may guess, I have many more individuals which also means many more variables. Instead, I would like to have a dataset of n*n observations with all the combinations of individuals being displayed. However, I am unsure whether this problem requires a reshape long command, because I don't understand what I am supposed to write as a _j variable. I also get the following error message:

    . reshape long freq length knows, i(name) j(s)
    variable s contains all missing values

    Did I miss something obvious or does this case require another command? Thanks a lot for your help.

  • #2
    You actually have it almost right:
    Code:
    reshape long freq length knows, i(name) j(s) string
    The suffixes that follow "knows", "freq," and "length" are not numbers, so the variable s will necessarily be a string variable. The -reshape- syntax requires you to say so in advance.

    Comment

    Working...
    X