Dear Statalists,

I have 2 columns (id and course)

I would like to create two types of adjacency matrices look like these:

1) Column headings for courses and row headings for id. The values inside the matrix equal 1 if the id attended the course, zero otherwise.

2) Both column headings and row headings for the ids, the values inside the matrix equals 1 if two ids attended the same course, zero otherwise. The diagonal equals zero (do not take into account the id itself).

Can anyone help me with this, please?

I really appreciate your help.

Kind regards,

Ken

I have 2 columns (id and course)

I would like to create two types of adjacency matrices look like these:

1) Column headings for courses and row headings for id. The values inside the matrix equal 1 if the id attended the course, zero otherwise.

341217 | 540103 | 340769 | ......... | 1199653 | ........ | |

1977 | 1 | 1 | 1 | .......... | 0 | ........ |

243Q | 0 | 0 | 0 | .......... | 1 | ........ |

... | ..... | .... | ... | ... | ... | ......... |

579Y | 0 | 0 | 0 | ....... | 0 | ....... |

1977 | 243Q | 3833 | ......... | 1199653 | ........ | |

1977 | 0 | 0 | 0 | .......... | 0 | ........ |

243Q | 0 | 0 | 0 | .......... | 1 | ........ |

... | ..... | .... | ... | ... | ... | ......... |

579Y | 0 | 1 | 0 | ....... | 0 | ....... |

I really appreciate your help.

Kind regards,

Ken

Code:

* Example generated by -dataex-. To install: ssc install dataex clear input str4 id str7 course "1977" "341217" "1977" "540103" "1977" "340769" "1977" "341355" "1977" "341168" "1977" "341583" "1977" "341582" "1977" "341374" "1977" "341423" "1977" "341118" "1977" "341132" "1977" "495892" "1977" "341153" "1977" "505279" "1977" "341386" "1977" "340825" "1977" "340871" "1977" "340791" "1977" "340842" "1977" "341438" "1977" "59796" "1977" "1617025" "243Q" "1199653" "243Q" "341811" "243Q" "485459" "243Q" "446218" "243Q" "341598" "243Q" "141620" "243Q" "36503" "243Q" "441141" "243Q" "1134308" "243Q" "508730" "243Q" "341830" "243Q" "341835" "243Q" "340891" "243Q" "341846" "243Q" "341863" "3833" "343997" "3833" "344018" "235B" "343977" "235B" "343997" "235B" "344018" "3833" "343982" "235B" "343982" "235B" "344099" "3833" "344099" "235B" "343983" "3833" "343983" "3833" "343977" "1314" "335777" "1314" "335735" "1314" "335863" "1314" "335561" "1314" "1307343" "1314" "335960" "1314" "1703887" "1314" "1328198" "1314" "335579" "1314" "512602" "1314" "335381" "1314" "1327143" "1314" "1250954" "1314" "1617193" "1314" "375960" "1314" "1672088" "1314" "1401213" "1314" "1207439" "1314" "335413" "1314" "342457" "1314" "377905" "1314" "985031" "1314" "1128721" "1314" "1250769" "1314" "335716" "1314" "335849" "1314" "335759" "1314" "336031" "1314" "1602281" "1314" "335949" "1314" "336009" "1314" "205455" "1314" "335877" "5535" "1054442" "5535" "886538" "5535" "346818" "5535" "1325730" "5535" "1461733" "5535" "1597384" "5535" "532609" "5535" "1321045" "5535" "627086" "5535" "1600118" "5535" "1596727" "5535" "1049576" "5535" "1367512" "5535" "1363494" "5535" "499359" "5535" "1809673" "5535" "1538194" "5535" "455960" "5535" "62737" "5535" "1763041" "5535" "1800512" "5535" "1095323" "5535" "347338" "5535" "1711058" "5535" "1313929" "5535" "1740625" "5535" "320934" "5535" "343699" "5535" "596870" "5535" "1772171" "5535" "347340" "5535" "837095" "5535" "653402" "5535" "372351" "5535" "497183" "5535" "325850" "5535" "87682" "5535" "1785362" "5535" "499576" "5535" "83621" "5535" "320920" "5535" "455796" "5535" "1203728" "5535" "1078585" "5535" "1858272" "5535" "1274835" "5535" "1656747" "5535" "499571" "5535" "87647" "5535" "545665" "5535" "803480" "5535" "321217" "5535" "541624" "5535" "831377" "5535" "1801001" "5535" "1785120" "5535" "1380041" "5535" "87637" "5535" "555878" "5535" "55417" "5535" "320933" "5535" "1072273" "5535" "1517333" "5535" "498031" "5535" "1795554" "5535" "1664080" "5535" "340013" "5535" "1716233" "5535" "1879911" "5535" "221228" "5535" "453830" "5535" "548662" "5535" "1890026" "5535" "510707" "5535" "1089194" "5535" "272463" "5535" "596233" "5535" "1836733" "5535" "553759" "5535" "1591164" "5535" "1371168" "5535" "206410" "5535" "1072590" "5535" "501271" "5535" "1335306" "554D" "373024" "554D" "345898" "554D" "499721" "554D" "346598" "554D" "346636" "554D" "346690" "554D" "342417" "554D" "607964" "554D" "517027" "554D" "346683" "554D" "346629" "554D" "346615" "554D" "346686" "554D" "607961" "554D" "345170" "554D" "346569" "554D" "457918" "554D" "509120" "579Y" "1669556" "579Y" "889136" "579Y" "1404877" "579Y" "1487736" "579Y" "534434" "579Y" "1831258" "579Y" "1523249" "579Y" "35454" "579Y" "33410" "579Y" "1251519" "579Y" "35458" "579Y" "1826538" "579Y" "1597413" "579Y" "1091764" "579Y" "33354" end

## Comment