Hi,
I'm using the dataset below and I'm looking to highlight potential clusters of kin members in specific socioeconomic contexts (variable context). Contexts vary through time (census) and dyads too. Dyads are based on the kinship typology (parent-children, siblings, uncles/aunts-nephews/nieces and so on). The example below contains only parent-child dyads, but I'm working at the population level (as opposed to the sample level), so I basically use all parent-child dyads there are in the census. The dyadic data is in long format: individuals can have repeated measures per dyad but also multiple dyads (one for each parent for example. I expect a heavy computation for cousins...).

My outcome variable "same_context" is dichotomous and take the value 1 if both members of the dyad inhabited the same context for a specific census year.

My first intuition (linked directly to my research question) is that individuals are nested in dyads and dyads are nested in contexts. The multiple membership aspect of the data seems to orientate towards a cross-classified model such as:

Code:
melogit same_context kin2 ego_sex i.contexts census c.census#c.census || all_: contexts || dyads:
.

However, I am still gathering information on how some variable should be entered in the model. For example, census. Should I treat census years as continuous or categorical? Should I remove level 3 and consider the contexts as a fixed effect? Should I add an interaction between contexts and censuses? I am not so sure that dyads are nested in contexts since and individual can share the same context with a parent and live in a different one with the other.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ego int census byte(head kin2 same_context ego_sex) long dyad
  338206 1851 1 2 1 2  6802706
 1099995 1901 0 1 1 2  1312353
  257008 1901 0 1 1 2  5266528
  951228 1851 0 1 1 1 10059236
16357573 1851 1 2 1 2  3318645
 5267049 1851 1 2 1 2  6609346
  684194 1901 1 2 1 2 11287570
 5217174 1851 1 2 1 2  6204950
  373954 1851 1 2 1 1  7549426
  311725 1911 0 1 1 2  6194640
  710997 1891 1 1 0 2  7776816
  383663 1851 1 2 1 2  7772531
 5275088 1851 1 2 1 2  6248381
  306768 1911 1 2 1 1  5978000
  951556 1851 0 1 1 1 10066321
 5217693 1851 1 1 1 1  9880621
 5276520 1851 1 2 1 2  5664898
  195739 1901 0 1 1 2  4112086
13750662 1851 1 2 1 2  2582236
27713833 1901 0 1 1 1  5701448
  257076 1901 1 2 1 2  5267683
  257076 1901 1 2 1 2  5267684
  645120 1891 1 2 1 1  5394379
 5241018 1851 1 2 1 2  6529679
 4946984 1851 0 1 1 1  9158261
 5279404 1851 1 2 1 1 10192162
  373122 1851 1 2 1 1  7530807
  370095 1851 1 1 1 1  7464433
  444352 1851 0 1 1 2  8649162
  660932 1891 1 2 1 2 11209418
  257472 1901 1 2 1 1  5274624
  264932 1901 0 1 1 1  5423727
 5270199 1851 1 2 1 1  6339448
  315126 1851 0 2 1 2  6253150
  375168 1851 0 1 1 1  7577446
  312427 1851 0 1 1 1  6208487
 5224191 1851 1 2 1 1  6850123
  297385 1901 0 1 1 1  5006557
 5284668 1891 0 2 0 1  9197727
  257090 1901 0 1 1 2  5268420
  257090 1901 0 1 1 2  5267683
 5006910 1901 1 2 1 2   221167
  265260 1901 0 1 1 1  5433181
 5220379 1851 1 2 1 1 10005576
  675516 1891 0 1 1 2  9767446
  340898 1851 0 1 1 1  6876136
12799872 1851 0 1 1 2  2374598
 5266286 1851 1 2 1 1 10136503
13274806 1851 0 2 1 1  2439377
  667476 1901 1 2 1 2 11236042
  799524 1901 0 1 1 1 11347361
  721804 1901 1 2 1 2  5272408
 4945367 1851 0 1 1 1  4509016
  752724 1901 0 1 1 2 11236040
  298552 1911 0 1 1 2  5263920
  382572 1851 0 1 1 2  7750740
 1002481 1851 0 1 1 2    40328
 5262181 1851 1 2 1 2 10127951
  649858 1851 0 1 1 1 10163854
  308499 1851 0 2 1 2  6142002
21183739 1851 0 1 1 2  4512689
  740819 1891 0 1 1 2 11474865
 1079814 1891 0 1 1 1  1009807
  329724 1851 0 1 1 1  6569600
 5247958 1851 1 2 1 2 10085211
  123808 1911 1 2 1 1  2272316
  999850 1901 0 1 1 1 12255826
 5270199 1851 1 2 1 1  6336069
  666904 1911 0 1 1 1 11233713
  386219 1851 0 1 1 1  7845697
  666889 1911 0 1 1 2  2272313
  374016 1891 1 2 1 2  1011673
  312311 1851 0 1 1 1  6205434
  666698 1911 0 1 1 2 11233040
 5205147 1861 1 2 1 2  9907211
 5218592 1851 0 2 1 1  6604722
  381093 1851 1 2 1 1  7707829
  374069 1851 1 1 1 2  7551878
 5237485 1851 1 2 1 1 10050149
  374069 1851 1 1 1 2  7551879
  312037 1851 0 1 1 1  6197251
  321373 1851 0 1 1 2  6354112
  379880 1851 1 2 1 2  7684181
 5180335 1851 1 2 1 2  9553229
  337108 1851 0 1 1 2  6763777
 5276438 1851 1 2 1 1 10175109
 5253312 1851 0 2 1 2 10104032
  312168 1851 0 1 1 1  6200988
16137591 1851 0 2 1 2  3253932
  232334 1891 0 2 1 1  4853724
14096308 1851 0 1 1 1  2687481
  292817 1901 0 1 1 2  5155525
16886330 1851 1 2 1 2  3480827
 5261016 1851 1 2 1 2 10125268
  356069 1861 1 2 1 2  4399020
 5242640 1851 1 2 1 2  6203283
13429804 1851 1 2 1 2  2485764
  537312 1891 0 1 1 2 10261856
  718906 1851 0 1 1 1 10136501
 5226037 1901 1 2 1 1 10030339
 5272913 1851 1 2 1 1  6468474
  316339 1851 0 1 1 1  6272912
 5279389 1851 1 2 1 2  6562023
  309993 1851 0 1 1 2  6168438
  325919 1861 0 1 1 1  6494578
  377881 1891 1 2 1 1  7642513
 5275477 1851 1 2 1 1  6305842
 5237478 1851 1 2 1 1  6890326
 5272662 1851 0 2 1 2  6269846
 5263784 1851 1 2 1 1 10130572
  639446 1851 0 1 1 2 10005575
 5028441 1851 1 2 1 1  8926946
  269302 1911 1 1 1 2  5525355
  791348 1901 1 2 0 2 11770420
26561949 1911 0 1 1 2  5441244
27103436 1911 0 1 1 1  5470411
 1061486 1901 1 2 1 1   701363
  635220 1851 0 1 1 1 10162839
  257274 1901 0 1 1 1  5271422
  299499 1901 1 2 1 1  6055649
  257274 1911 0 1 1 1  5271422
  374076 1851 0 1 1 2  7552065
  321510 1851 0 1 1 1  6358904
  321427 1851 0 1 1 1  6355842
 5202965 1851 1 2 1 2  9895819
  730880 1901 1 2 1 1   294746
  299521 1901 0 1 1 1  4892785
  700129 1891 1 2 1 2 11372085
  257281 1911 1 2 1 2  5271607
 5276894 1851 1 2 1 1 10179632
  257281 1911 1 2 1 2  5271613
 5272708 1851 1 2 1 2  6222786
  332677 1851 0 1 1 1  6635695
  257282 1901 0 1 1 1  5271823
  257282 1911 0 1 1 1  5271823
  880068 1901 0 1 1 1  1890756
  316148 1851 0 1 1 2  6268608
  328184 1851 0 1 1 1  6544802
  446990 1851 0 1 1 2  8684272
 5246371 1851 1 2 1 2 10078237
  374077 1851 1 1 1 1  7552402
  640865 1851 0 1 1 2 11108145
 5176292 1851 1 2 1 1  9219206
 5217358 1851 1 2 1 2  6168203
  305371 1911 0 1 1 2  6103746
 5280822 1851 1 1 1 2 10125543
 5246295 1851 0 2 1 2  6592573
  257342 1901 0 1 1 2  5272739
 5237418 1851 1 2 1 1  6543648
  317780 1851 0 1 1 1  6301860
  257343 1901 0 1 1 1  5272923
  257343 1911 0 1 1 1  5272923
  257343 1911 0 1 1 1  5272896
  654045 1851 0 1 1 1 10209145
  370423 1851 1 2 1 2  7467058
  733443 1891 0 1 1 2  9274374
  705542 1891 1 1 1 1  6169282
  251868 1901 1 2 0 1  5131798
  257342 1901 0 1 1 2  5272766
  863936 1901 1 1 1 2 11937381
  267938 1911 1 1 0 1  5494055
  807113 1911 0 1 1 1 11516292
  717380 1911 1 2 1 1 11459025
 5278062 1851 1 1 1 2 10042172
  651740 1851 0 1 1 1 10164809
 5276520 1851 1 2 1 2 10176149
  335520 1851 1 2 1 1  6706319
 5208564 1851 0 2 1 2  7146125
 5276766 1851 1 2 1 2 10178214
  249052 1911 1 2 1 2  5091129
 5247966 1851 1 2 1 1 10085415
  723146 1891 1 2 1 1 11488594
 5239995 1851 1 2 1 2  6137131
  700082 1891 1 2 1 2  5644691
33741263 1851 0 1 1 1  6613428
  341479 1851 0 1 1 1  6887545
  257472 1901 1 2 1 1  5273852
  864066 1901 1 2 1 2 11937328
  324210 1851 0 1 1 2  6437018
  257472 1901 1 2 1 1  5273385
 5218639 1851 1 2 1 2  6697697
  398833 1891 1 2 1 2  7978038
  201276 1901 0 1 1 1  4205906
  320138 1851 0 1 1 1  6332944
27177891 1911 0 1 1 1  4894039
  242752 1891 1 1 0 2  4994124
  332418 1851 0 1 1 1  6630345
  710180 1851 0 1 1 2 11079241
  951236 1851 0 1 1 1 10059238
  253218 1901 0 1 1 1  5157625
  950793 1851 0 1 1 2 10099470
  645830 1901 1 2 1 2  5730039
  723161 1851 0 1 1 2  9765611
  374152 1851 0 1 1 1  7555352
 5272982 1851 1 2 1 2 10160320
13769356 1851 1 2 1 2  2587382
  345290 1851 0 1 1 2  6972688
  715900 1911 1 2 1 1  6084246
  308117 1851 0 1 1 2  6132177
 5240179 1851 1 2 1 2  6721911
  332364 1851 0 1 1 2  6629561
 5247958 1851 1 2 1 2 10085212
   61974 1901 0 1 1 2 10402303
 5224191 1861 1 2 1 1  6852632
  311649 1911 0 1 1 2  6193545
  738065 1911 0 2 1 2 11556390
  667811 1891 1 2 1 1 11238674
  272056 1891 0 1 1 1  5585092
 5246669 1851 1 2 1 1  6215399
  372787 1851 1 2 1 1  4910298
  163804 1911 1 2 1 2  3327393
  310573 1911 0 1 1 2  6174930
  720461 1851 0 2 1 1 11475975
 5219112 1851 0 2 1 2  6178499
  258289 1911 1 1 0 2  5282373
  734785 1901 0 1 1 1 11347828
  374160 1851 1 2 1 1  6789237
 1129039 1891 0 1 1 1  1776792
28554236 1891 0 1 1 1  5814716
  343278 1851 0 1 1 1  6928865
11946596 1851 1 2 1 1  2156753
  636944 1851 0 1 1 1 10050147
 5237485 1851 1 2 1 1 10050144
 5218449 1851 1 2 1 2  9994145
  374198 1851 0 1 1 1  7556292
  952074 1861 0 1 1 1 10167850
  317308 1851 0 1 1 1  6287872
 5208563 1851 0 2 1 1  7146124
  246284 1891 1 2 1 2  5034033
 5246623 1851 1 2 1 1  6301526
  339098 1851 0 2 1 2  6830086
  376585 1851 0 1 1 2  7525824
20335321 1851 0 1 1 1  4266812
  719089 1911 1 2 1 2  5352148
  643436 1851 0 1 1 1 10200368
 5246760 1851 1 1 1 2 10081183
  386240 1851 1 2 1 2  7847410
 5278177 1851 1 2 1 2 10186161
  716275 1851 0 1 1 2 10150065
  951120 1851 0 1 1 1 10144732
  314035 1911 0 1 1 2  6234662
  340326 1851 0 1 1 1  6664397
  340906 1851 0 1 1 2  6876245
  640560 1851 0 1 1 1 10186539
 1071379 1891 0 1 1 2   887950
 5213322 1851 1 2 1 1  9955665
 5210676 1851 1 2 1 1  8642417
  646333 1851 0 1 1 1 10202596
  717358 1911 1 1 1 2 11147369
  347281 1891 1 2 1 1  1008953
end
label values kin2 role
label def role 1 "Parent", modify
label def role 2 "Children", modify
label values same_context same_context
label def same_context 0 "No", modify
label def same_context 1 "Yes", modify
label values ego_sex sex
label def sex 1 "Male", modify
label def sex 2 "Female", modify