I had earlier posted a different question about my data here. Where Clyde helpfully suggested that m:m should not be performed.
I will hereby post examples of both of my datasets:
Household data
Air pollution data
The household dataset contains individual child observations which each have a unique CID. Each child lives in a certain district, denoted by DNAME. The household data is each year, no month is specified. The dependent variables for my research are C_ARITH, C_ENGL & C_READ.
The air pollution dataset contains district-level data, with the mean pollution levels per district per month of each year. This dataset contains more years of data than the household dataset in order to be able to calculate lead- and lag effects of pollution on the dependent variables.
The merge should result in a dataset where individual household observations are assigned (monthly) variables about air pollution based on the district they live in and the year of the survey.
How should I proceed?
I previously tried to do a m:m merge on year and DNAME.
However since Clyde advice against a m:m merge, I am unsure about how to proceed.
Thanks for your advice!
I will hereby post examples of both of my datasets:
Household data
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year str19 DNAME long CID byte(C_AGE C_SEX C_READ C_ENGL C_ARITH) 2019 "ASTORE" 104534 11 1 5 5 6 2019 "ASTORE" 104475 6 0 . . . 2019 "ASTORE" 104569 15 1 5 5 6 2019 "ASTORE" 103761 8 0 5 5 6 2019 "ASTORE" 104121 7 0 5 . 6 2019 "ASTORE" 103441 10 1 5 5 6 2019 "ASTORE" 104453 10 0 5 5 6 2019 "ASTORE" 104215 5 0 3 4 5 2019 "ASTORE" 104142 16 0 5 5 6 2019 "ASTORE" 103601 4 1 . . . 2019 "ASTORE" 103431 12 1 5 5 6 2019 "ASTORE" 104635 4 0 . . . 2019 "ASTORE" 103550 5 1 2 3 3 2019 "ASTORE" 103773 9 0 5 5 6 2019 "ASTORE" 104613 3 0 . . . 2019 "ASTORE" 103184 6 1 1 1 1 2019 "ASTORE" 104292 10 0 3 5 6 2019 "ASTORE" 104327 12 0 5 5 6 2019 "ASTORE" 103354 8 0 4 4 5 2019 "ASTORE" 103546 6 0 1 1 1 2019 "ASTORE" 104577 12 0 5 5 6 2019 "ASTORE" 104474 3 0 . . . 2019 "ASTORE" 103992 14 1 1 1 1 2019 "ASTORE" 103074 7 0 5 5 6 2019 "ASTORE" 103357 8 1 5 5 6 2019 "ASTORE" 104180 5 0 4 4 4 2019 "ASTORE" 104028 9 1 5 2 6 2019 "ASTORE" 104030 7 1 4 1 5 2019 "ASTORE" 104043 8 1 5 5 6 2019 "ASTORE" 103805 5 0 2 2 2 2019 "ASTORE" 103429 10 0 5 5 6 2019 "ASTORE" 104270 16 1 5 5 6 2019 "ASTORE" 104212 12 0 5 5 6 2019 "ASTORE" 103314 10 0 5 5 6 2019 "ASTORE" 104507 3 0 . . . 2019 "ASTORE" 104060 3 1 . . . 2019 "ASTORE" 104101 10 0 5 5 6 2019 "ASTORE" 103134 8 1 4 5 6 2019 "ASTORE" 104302 8 0 4 4 5 2019 "ASTORE" 103180 14 1 5 4 6 2019 "ASTORE" 103078 3 1 . . . 2019 "ASTORE" 103782 12 0 5 5 6 2019 "ASTORE" 103341 8 0 5 4 6 2019 "ASTORE" 103585 10 0 5 1 6 2019 "ASTORE" 104406 12 0 5 5 5 2019 "ASTORE" 103715 16 0 5 5 6 2019 "ASTORE" 103574 15 0 5 5 5 2019 "ASTORE" 104416 10 0 5 5 6 2019 "ASTORE" 103511 3 0 . . . 2019 "ASTORE" 104651 14 0 5 5 6 2019 "ASTORE" 104237 8 0 5 5 6 2019 "ASTORE" 103126 8 1 5 5 6 2019 "ASTORE" 104258 12 1 5 5 6 2019 "ASTORE" 103777 4 1 . . . 2019 "ASTORE" 103139 16 1 5 5 6 2019 "ASTORE" 104347 7 1 3 3 4 2019 "ASTORE" 104603 14 0 5 5 6 2019 "ASTORE" 104572 8 0 1 1 1 2019 "ASTORE" 103238 5 0 1 1 1 2019 "ASTORE" 103487 7 0 2 3 4 2019 "ASTORE" 103560 8 0 3 1 3 2019 "ASTORE" 104294 5 0 1 1 1 2019 "ASTORE" 104615 3 0 . . . 2019 "ASTORE" 104496 10 0 1 1 1 2019 "ASTORE" 104493 12 0 5 5 5 2019 "ASTORE" 103656 10 0 5 5 6 2019 "ASTORE" 104192 16 1 5 5 5 2019 "ASTORE" 104324 7 0 3 4 5 2019 "ASTORE" 103330 9 0 5 5 6 2019 "ASTORE" 104722 8 0 1 1 1 2019 "ASTORE" 103592 13 0 5 4 6 2019 "ASTORE" 104395 6 1 2 3 4 2019 "ASTORE" 103997 14 1 5 5 6 2019 "ASTORE" 103882 14 1 5 5 6 2019 "ASTORE" 104476 8 0 5 5 6 2019 "ASTORE" 103638 10 2 1 1 1 2019 "ASTORE" 103859 5 0 2 2 2 2019 "ASTORE" 103197 10 1 5 5 6 2019 "ASTORE" 103483 4 0 . . . 2019 "ASTORE" 103510 5 0 1 1 1 2019 "ASTORE" 104646 13 1 5 5 6 2019 "ASTORE" 103958 4 1 . . . 2019 "ASTORE" 104358 7 0 4 1 5 2019 "ASTORE" 103823 11 0 5 5 6 2019 "ASTORE" 103688 6 1 . . . 2019 "ASTORE" 104524 16 0 5 5 6 2019 "ASTORE" 103203 15 1 5 5 6 2019 "ASTORE" 104218 16 0 4 5 . 2019 "ASTORE" 103687 10 1 5 5 6 2019 "ASTORE" 103043 3 1 . . . 2019 "ASTORE" 103678 14 1 1 1 1 2019 "ASTORE" 103233 12 1 5 4 5 2019 "ASTORE" 103166 9 1 5 5 6 2019 "ASTORE" 104723 6 0 4 4 3 2019 "ASTORE" 104571 8 0 1 1 1 2019 "ASTORE" 103311 5 0 1 1 1 2019 "ASTORE" 104452 3 0 . . . 2019 "ASTORE" 103517 10 1 5 5 6 2019 "ASTORE" 103731 3 1 . . . 2019 "ASTORE" 104029 5 0 3 4 4 end label values C_SEX C_SEX_lbl label def C_SEX_lbl 0 "Male", modify label def C_SEX_lbl 1 "Female", modify label values C_ENGL C_ENGL_lbl label def C_ENGL_lbl 1 "Beginner/Nothing", modify label def C_ENGL_lbl 2 "Capital letters", modify label def C_ENGL_lbl 3 "Small letters", modify label def C_ENGL_lbl 4 "Words", modify label def C_ENGL_lbl 5 "Sentences", modify label values C_ARITH C_ARITH_lbl label def C_ARITH_lbl 1 "Beginner/Nothing", modify label def C_ARITH_lbl 2 "Recognition of 1-9", modify label def C_ARITH_lbl 3 "Recognition of 10-99", modify label def C_ARITH_lbl 4 "Recognition of 100-200", modify label def C_ARITH_lbl 5 "Subtraction", modify label def C_ARITH_lbl 6 "Division", modify label var year "SYEAR" label var DNAME "DNAME" label var CID "CID" label var C_AGE "C_AGE" label var C_SEX "Gender of the child" label var C_READ "Reading in Local/National language" label var C_ENGL "Highest learning level of child in English." label var C_ARITH "Highest learning level of child in Arithmetic."
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(year month modate) str25 DNAME float comean double no2mean float(pm25mean so2mean hummean precmean tempmean TI_Count average_diff) 2011 1 612 "Bagh" 87.17934 1.370e+15 1.28e-08 2.83e-09 .003127968 1.1696461 3.866799 0 -3.9859924 2011 2 613 "Bagh" 91.09612 1.610e+15 1.93e-08 2.14e-09 .004525435 11.461983 4.0603547 12 -4.060998 2011 3 614 "Bagh" 87.0575 1.420e+15 2.12e-08 1.84e-09 .006319631 3.2977514 10.610514 0 -4.098527 2011 4 615 "Bagh" 87.0575 1.420e+15 2.12e-08 1.84e-09 .007800096 3.0574124 13.949953 4 -4.3325086 2011 5 616 "Bagh" 96.89316 1.440e+15 1.78e-08 1.62e-09 .009111885 1.23322 22.08506 0 -4.3246684 2011 6 617 "Bagh" 98.6109 2.030e+15 4.32e-08 1.53e-09 .011554516 .011838347 23.15986 4 -4.3497868 2011 7 618 "Bagh" 94.11146 1.600e+15 4.60e-08 1.06e-09 .014972327 6.880902 21.223934 0 -4.3655386 2011 8 619 "Bagh" 94.68835 7.640e+14 2.83e-08 8.78e-10 .01569618 9.354296 20.463957 0 -4.3588743 2011 9 620 "Bagh" 88.77015 9.940e+14 2.10e-08 1.33e-09 .012881536 3.062021 18.628471 4 -4.2478113 2011 10 621 "Bagh" 83.31566 1.010e+15 2.07e-08 2.21e-09 .007134011 .6190753 15.21117 0 -4.280564 2011 11 622 "Bagh" 80.98125 1.240e+15 1.69e-08 2.53e-09 .00527302 1.1745063 11.935515 4 -4.1260953 2011 12 623 "Bagh" 87.18204 1.090e+15 1.60e-08 3.04e-09 .003115135 1.0088751 6.786922 0 -4.023637 2012 1 624 "Bagh" 92.54285 1213482712170496 1.9973905e-08 2.694217e-09 .003151011 3.60239 1.976028 0 -3.997411 2012 2 625 "Bagh" 94.17786 1651238663880704 2.6739974e-08 2.119005e-09 .003935738 6.656986 2.990808 8 -3.948461 2012 3 626 "Bagh" 89.34711 1923520296648704 4.118444e-08 2.103637e-09 .005118794 2.77118 9.004811 0 -4.066264 2012 4 627 "Bagh" 85.55315 1377365410185216 1.9160225e-08 1.439295e-09 .008139996 3.449885 13.582783 4 -4.256367 2012 5 628 "Bagh" 93.66323 1484169502785536 1.6818568e-08 1.450042e-09 .008624663 1.0974368 18.946047 0 -4.40973 2012 6 629 "Bagh" 89.9923 2322958160756736 2.2464176e-08 1.272671e-09 .007725833 .4800621 23.47219 4 -4.335492 2012 7 630 "Bagh" 96.36054 1990996984332288 3.926007e-08 1.382495e-09 .013052827 1.6001686 23.59337 0 -4.3446145 2012 8 631 "Bagh" 91.70353 1486034122571776 3.938829e-08 1.134257e-09 .015443794 6.004316 21.104954 0 -4.300043 2012 9 632 "Bagh" 86.64808 709125138808832 2.1461503e-08 1.394257e-09 .012638452 4.914126 18.500006 4 -4.262113 2012 10 633 "Bagh" 82.67539 1992372044955648 1.596188e-08 2.075942e-09 .006487353 .3261698 14.36064 0 -4.2243185 2012 11 634 "Bagh" 80.58346 2187282694012928 1.9703734e-08 2.356162e-09 .004225512 .772775 10.42697 4 -4.0962276 2012 12 635 "Bagh" 84.7132 2212265914793984 2.10318e-08 2.640241e-09 .0035673245 2.835265 6.896488 0 -3.999688 2013 1 636 "Bagh" 88.14882 1.43485e+15 3.38527e-08 2.84644e-09 .003168737 1.939727 4.069512 0 -4.087565 2013 2 637 "Bagh" 88.97813 1.38544e+15 2.12863e-08 2.30604e-09 .004725732 10.852698 5.107724 12 -4.0672083 2013 3 638 "Bagh" 82.49726 1.44797e+15 1.9406e-08 2.08583e-09 .006899995 3.105056 11.148764 0 -4.193263 2013 4 639 "Bagh" 84.90105 1.70056e+15 1.91698e-08 1.60761e-09 .008349918 .978727 14.462934 4 -4.3708396 2013 5 640 "Bagh" 87.36565 1.79451e+15 1.92258e-08 1.42456e-09 .008495155 .436298 20.53282 0 -4.3437257 2013 6 641 "Bagh" 88.56911 1.67749e+15 2.93205e-08 1.43239e-09 .01107857 2.2108924 23.47961 4 -4.3087754 2013 7 642 "Bagh" 94.32934 1.70467e+15 4.26452e-08 1.10985e-09 .015565437 4.3432565 22.15843 0 -4.37462 2013 8 643 "Bagh" 93.27677 6.56289e+14 3.01487e-08 1.05225e-09 .015790226 10.545626 20.219236 0 -4.3856983 2013 9 644 "Bagh" 92.97852 1.53361e+15 3.76056e-08 1.49855e-09 .01236818 2.818759 18.473186 4 -4.2893515 2013 10 645 "Bagh" 84.33326 9.63012e+14 3.16654e-08 1.90718e-09 .008449645 .796231 15.827604 0 -4.2110353 2013 11 646 "Bagh" 80.77211 1.53196e+15 1.61689e-08 2.32661e-09 .003981657 1.0914773 10.568498 4 -4.0631094 2013 12 647 "Bagh" 84.74134 1.76257e+15 1.95795e-08 2.62321e-09 .002851172 .57528985 6.718508 0 -3.9797506 2014 1 648 "Bagh" 85.21386 1321478926630912 1.207336e-08 2.651676e-09 .00313978 1.1320031 5.004186 0 -3.8397684 2014 2 649 "Bagh" 89.56825 938583867260928 2.415155e-08 2.201597e-09 .003844974 4.688405 4.7114954 12 -4.0005713 2014 3 650 "Bagh" 86.72038 1562112690225152 2.3130315e-08 1.617281e-09 .005940275 8.582874 8.0801525 0 -4.1475873 2014 4 651 "Bagh" . 1669715982286848 1.4075296e-08 1.436485e-09 .007837898 3.665759 13.72976 4 -4.1492195 2014 5 652 "Bagh" 91.98306 2213897868148736 2.1218913e-08 1.326236e-09 .009697257 1.948653 18.486076 0 -4.3637557 2014 6 653 "Bagh" 87.15491 1797170143428608 2.779732e-08 1.309768e-09 .009770347 .23367853 23.834375 4 -4.259127 2014 7 654 "Bagh" 91.82771 1738933138358272 4.959615e-08 1.272194e-09 .014765512 5.969679 22.429613 0 -4.396477 2014 8 655 "Bagh" 87.97823 1580905051193344 4.000032e-08 1.318746e-09 .014372448 3.6941996 20.801445 0 -4.2910438 2014 9 656 "Bagh" 90.11967 1370824879636480 2.706414e-08 1.434484e-09 .013294342 5.507071 18.285784 4 -4.2718487 2014 10 657 "Bagh" 85.62978 1504632203378688 2.557196e-08 2.127297e-09 .008168736 .7135426 14.669197 0 -4.1769924 2014 11 658 "Bagh" 81.5078 1004572583657472 1.671437e-08 2.34133e-09 .0045229862 3.488017 10.963312 4 -4.1058745 2014 12 659 "Bagh" 90.72 1975702874226688 1.806155e-08 3.02111e-09 .002959271 .05335829 7.737238 0 -4.016124 2015 1 660 "Bagh" 95.47401 1.59479e+15 2.31832e-08 2.73419e-09 .003192125 1.9521163 5.684761 0 -4.028019 2015 2 661 "Bagh" 94.07554 1.25028e+15 2.70163e-08 2.50889e-09 .004779678 8.310263 6.878791 12 -4.0533495 2015 3 662 "Bagh" 91.07442 1.70294e+15 2.10845e-08 1.75401e-09 .006707262 10.03192 8.832126 0 -4.148861 2015 4 663 "Bagh" 90.42397 1.52653e+15 2.34951e-08 1.65462e-09 .009787794 4.3130617 14.528955 4 -4.2771583 2015 5 664 "Bagh" 91.87411 1.99664e+15 2.00569e-08 1.49132e-09 .010611065 .7848894 19.807613 0 -4.3881235 2015 6 665 "Bagh" 90.01115 2.5208e+15 2.37773e-08 1.41252e-09 .011354707 2.1904905 21.490427 4 -4.3949633 2015 7 666 "Bagh" 95.15714 1.52115e+15 4.07979e-08 1.1332e-09 .016110012 8.216532 21.37282 0 -4.4067082 2015 8 667 "Bagh" 90.6526 1.71113e+15 3.27492e-08 1.17149e-09 .015513403 6.43141 20.305904 0 -4.292745 2015 9 668 "Bagh" 91.18709 1.60216e+15 1.67013e-08 1.70442e-09 .010465883 5.070981 18.652908 4 -4.309525 2015 10 669 "Bagh" 87.68997 1.41633e+15 2.25203e-08 2.13589e-09 .007712538 2.860581 14.973003 0 -4.2506394 2015 11 670 "Bagh" 93.82375 2.31724e+15 2.26985e-08 2.91446e-09 .005785976 2.4009426 10.178153 4 -4.204908 2015 12 671 "Bagh" 88.40134 1.44959e+15 1.89977e-08 3.04636e-09 .004373158 1.054227 6.789611 0 -4.0991936 2016 1 672 "Bagh" 89.19608 1616098348761088 2.027608e-08 2.749651e-09 .004250266 2.7115405 5.903308 0 -4.170458 2016 2 673 "Bagh" 97.50085 927706124386304 2.0700513e-08 2.92747e-09 .00477201 2.0795426 8.013728 8 -4.035442 2016 3 674 "Bagh" 88.66555 956567432200192 2.312301e-08 1.892909e-09 .007230157 11.160146 10.407402 0 -4.184724 2016 4 675 "Bagh" 83.81638 2181041636769792 1.8102016e-08 1.631641e-09 .0094289 1.497066 15.41734 4 -4.3061914 2016 5 676 "Bagh" 92.90459 2386589242097664 2.481389e-08 1.356736e-09 .010680747 1.567482 21.27681 0 -4.3301845 2016 6 677 "Bagh" 93.44053 2179736503582719.8 3.4619948e-08 1.387683e-09 .012849852 .5531863 23.800547 4 -4.341146 2016 7 678 "Bagh" 90.54871 1632678935789568 4.002403e-08 1.063075e-09 .015610992 8.554562 21.814747 0 -4.3762736 2016 8 679 "Bagh" 92.09718 1616700113944576 2.0619135e-08 1.146415e-09 .015145776 6.245529 20.5169 0 -4.3861656 2016 9 680 "Bagh" 89.04362 1653426177966080 3.606842e-08 1.747257e-09 .012386053 2.6152856 19.191677 4 -4.2304864 2016 10 681 "Bagh" 86.99828 1153376121257984 3.0299812e-08 2.293747e-09 .00693867 .13529702 16.39858 0 -4.2311153 2016 11 682 "Bagh" 96.48254 2144521596960768 3.799113e-08 2.813907e-09 .003335137 .13115884 12.600725 4 -3.97206 2016 12 683 "Bagh" 95.28899 1999163394883584 2.72796e-08 3.118837e-09 .002608434 .04939467 10.963993 0 -3.976992 2017 1 684 "Bagh" 97.2655 3133651759923200 2.353207e-08 2.781802e-09 .003899978 10.22799 2.209425 0 -3.8157685 2017 2 685 "Bagh" 93.16988 775373600063488.1 1.6407757e-08 2.869919e-09 .005185057 4.971684 6.21266 12 -3.888585 2017 3 686 "Bagh" 86.10243 578040807555072 2.097392e-08 1.578811e-09 .006854673 4.148264 9.1480875 0 -4.0602155 2017 4 687 "Bagh" 84.08228 1541824539787264 2.588715e-08 1.510895e-09 .009454248 5.532279 16.187765 4 -4.2857304 2017 5 688 "Bagh" 94.94907 2601653354102784 2.525729e-08 1.475436e-09 .010794267 .6998675 20.553614 0 -4.401654 2017 6 689 "Bagh" 91.51187 2134342860013568 4.232872e-08 1.384116e-09 .01230925 4.2286587 22.1469 4 -4.367141 2017 7 690 "Bagh" 93.95013 1869428538998784 3.980618e-08 1.048432e-09 .016079564 7.330976 21.574024 0 -4.354427 2017 8 691 "Bagh" 91.38566 1720190437949440 4.518098e-08 1.328456e-09 .015140137 4.7383447 20.83118 0 -4.2887754 2017 9 692 "Bagh" 90.4781 1887291173765120 2.6163583e-08 1.646634e-09 .011051876 2.5170274 19.09372 4 -4.2901754 2017 10 693 "Bagh" 91.05032 1155190140960768 4.078146e-08 2.408569e-09 .005751996 .028918317 16.934206 0 -4.2425785 2017 11 694 "Bagh" 97.14627 2172625111482368 4.539849e-08 3.224996e-09 .0037931255 .51798505 10.77063 4 -4.0305734 2017 12 695 "Bagh" 90.47581 1883981163266048.3 1.4419516e-08 2.925485e-09 .00347747 1.3165545 7.327122 0 -3.8749466 2018 1 696 "Bagh" 93.36389 1088348101804032 2.582001e-08 3.078299e-09 .003070038 .6975487 6.413716 0 -3.8943734 2018 2 697 "Bagh" 92.23473 1476527145353216 2.196152e-08 2.494247e-09 .0043228734 4.804201 7.1619 12 -4.0322847 2018 3 698 "Bagh" 86.18471 995302064521216 2.179972e-08 1.831236e-09 .006138324 2.908453 12.29359 0 -4.1187353 2018 4 699 "Bagh" 86.29247 887766686629888 3.213903e-08 1.651941e-09 .008195323 7.128837 15.766562 4 -4.2047443 2018 5 700 "Bagh" 92.3371 1731940931600384 3.041294e-08 1.574394e-09 .00906693 1.838588 19.016413 0 -4.2863297 2018 6 701 "Bagh" 93.35083 2476867374284800 4.49902e-08 1.538027e-09 .010944417 1.8576046 23.163395 4 -4.321526 2018 7 702 "Bagh" 88.771 1669264876503040 4.689268e-08 1.137032e-09 .016026296 10.900517 21.181334 0 -4.43627 2018 8 703 "Bagh" 88.9365 1964027945156608 6.038479e-08 1.13786e-09 .01637044 8.943795 20.527534 0 -4.3211327 2018 9 704 "Bagh" 91.99292 1894493297049600 3.854441e-08 1.815003e-09 .012213907 3.904359 18.550716 4 -4.314157 2018 10 705 "Bagh" 86.96629 1558247756529664 2.2696774e-08 2.513549e-09 .006886619 .50373423 14.196733 0 -4.184308 2018 11 706 "Bagh" 85.52283 2457764836147200 2.373712e-08 2.676921e-09 .005159461 1.346202 10.265257 4 -4.062054 2018 12 707 "Bagh" 86.91177 1233642718232576 2.0373603e-08 2.756682e-09 .0034888526 1.1144037 6.463125 0 -3.827928 2019 1 708 "Bagh" 89.98477 1424298396876800 2.334096e-08 2.487495e-09 .0037370615 7.79283 1.8268626 0 -3.8439875 2019 2 709 "Bagh" 97.97309 1255141109923840 2.3679467e-08 2.895977e-09 .004481537 8.719969 2.717334 12 -3.8924375 2019 3 710 "Bagh" 90.87844 851415408836608 2.3279336e-08 2.032633e-09 .006637315 5.699942 7.861566 0 -4.004024 2019 4 711 "Bagh" 85.86795 1523456843710464 2.4165994e-08 1.646448e-09 .01012094 5.68907 15.33409 4 -4.187106 end format %tm modate label var DNAME "Name of the district"
The air pollution dataset contains district-level data, with the mean pollution levels per district per month of each year. This dataset contains more years of data than the household dataset in order to be able to calculate lead- and lag effects of pollution on the dependent variables.
The merge should result in a dataset where individual household observations are assigned (monthly) variables about air pollution based on the district they live in and the year of the survey.
How should I proceed?
I previously tried to do a m:m merge on year and DNAME.
However since Clyde advice against a m:m merge, I am unsure about how to proceed.
Thanks for your advice!
Comment