I am trying to automate the following where I am attempting to create a variable for each unique pair, where AB == BA, across the variables input*
I first sort the data using the user command from https://www.stata-journal.com/sjpdf....iclenum=pr0046
I can do it manually but was wondering if there is a more automated solution which will work better for larger datasets.
Finally I want to see the frequencies these occur which is why I sorted in the first place
Code:
clear input id date str3 input1 str3 input2 str3 input3 str3 input4 1 18263 "A" "B" "C" "E" 2 18264 "B" "D" "A" 3 18264 "B" "C" "E" 4 18265 "C" "A" "B" "R" 5 18267 "C" "B" "E" "L" 6 18268 "A" 7 18269 "E" "C" "E" 8 18271 "R" "D" 9 18272 "B" "R" "D" 10 1827 "B" "L" "A" 11 18274 "R" "A" "C" end
Code:
rowsort input1-input4, generate(inputs_alpha1-inputs_alpha4) highmissing
Code:
g grp1 = inputs_alpha1+inputs_alpha2 g grp2 = inputs_alpha1+inputs_alpha3 g grp3 = inputs_alpha1+inputs_alpha4 g grp4 = inputs_alpha2+inputs_alpha3 g grp5 = inputs_alpha2+inputs_alpha4 g grp6 = inputs_alpha3+inputs_alpha4
Comment