Dear Statalisters,
I would like to efficiently convert the following data:
into this format:
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.
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
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
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.
Comment