I am working a matched case-control study (matched on age and sex). In the below example data set, "case_id" is ID for cases and "control_id" is ID of controls for their respective cases. I would like to add a new row for each case in each group so that I can identify case and controls in each group for further calculations. Please kindly suggest me how I can do it. I am using Stata 16.1.
The example data set and the desired data (in table) are as below;
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long case_id str4 birth_yr str1 sex long control_id byte drawing 2 "1939" "2" 376946 1 2 "1939" "2" 2942780 2 2 "1939" "2" 47779 3 3 "1988" "2" 3315976 5 3 "1988" "2" 1046611 1 3 "1988" "2" 2263204 4 3 "1988" "2" 174519 3 3 "1988" "2" 2698292 2 5 "1933" "1" 570729 2 5 "1933" "1" 1473493 1 5 "1933" "1" 1713036 3 18 "1948" "1" 2549094 5 18 "1948" "1" 445970 2 18 "1948" "1" 893367 1 18 "1948" "1" 2310288 3 18 "1948" "1" 766227 4 21 "1920" "2" 2136179 1 21 "1920" "2" 3706241 3 21 "1920" "2" 400520 2 27 "1938" "1" 1278141 2 27 "1938" "1" 3137797 1 35 "1943" "1" 3689694 1 35 "1943" "1" 3049360 3 35 "1943" "1" 1701121 2 37 "1982" "2" 2254857 3 37 "1982" "2" 3657569 4 37 "1982" "2" 1137049 1 37 "1982" "2" 20248 5 37 "1982" "2" 3312689 2 41 "1931" "1" 2936236 2 41 "1931" "1" 1279751 1 42 "1918" "1" 3884722 1 42 "1918" "1" 710923 4 42 "1918" "1" 3143734 2 42 "1918" "1" 217435 3 42 "1918" "1" 1925103 5 44 "1944" "1" 263386 2 44 "1944" "1" 3640281 1 44 "1944" "1" 4024601 5 44 "1944" "1" 3604175 4 44 "1944" "1" 4027191 3 45 "1989" "1" 2548475 4 45 "1989" "1" 1730091 5 45 "1989" "1" 2545426 3 45 "1989" "1" 1716034 2 45 "1989" "1" 2536701 1 47 "1977" "2" 916222 4 47 "1977" "2" 2907055 2 47 "1977" "2" 803776 1 47 "1977" "2" 3945266 5 47 "1977" "2" 1722669 3 59 "1925" "2" 2757129 3 59 "1925" "2" 43313 1 59 "1925" "2" 2515262 2 59 "1925" "2" 3803170 4 60 "1944" "2" 3864710 2 60 "1944" "2" 1587805 1 60 "1944" "2" 3314789 3 60 "1944" "2" 1598217 4 69 "1953" "2" 2615813 5 69 "1953" "2" 1368929 2 69 "1953" "2" 519307 3 69 "1953" "2" 1302334 1 69 "1953" "2" 2876821 4 72 "1934" "2" 2881280 2 72 "1934" "2" 2290634 1 72 "1934" "2" 388080 3 74 "1929" "1" 3710540 1 74 "1929" "1" 2914260 2 75 "1987" "2" 428090 3 75 "1987" "2" 1797948 2 75 "1987" "2" 1196924 1 75 "1987" "2" 1554935 4 75 "1987" "2" 2819514 5 79 "1961" "2" 1790102 3 79 "1961" "2" 3069242 2 79 "1961" "2" 80233 1 79 "1961" "2" 2920718 4 79 "1961" "2" 654452 5 82 "1940" "1" 786277 2 82 "1940" "1" 84262 1 83 "1946" "1" 1728796 5 83 "1946" "1" 2562225 3 83 "1946" "1" 2923787 1 83 "1946" "1" 396347 2 83 "1946" "1" 3636393 4 85 "1973" "2" 3597618 4 85 "1973" "2" 3059310 5 85 "1973" "2" 312933 3 85 "1973" "2" 765396 1 85 "1973" "2" 727242 2 87 "1986" "2" 1235065 5 87 "1986" "2" 3885966 2 87 "1986" "2" 323953 4 87 "1986" "2" 33525 1 87 "1986" "2" 37721 3 88 "1924" "1" 3543505 2 88 "1924" "1" 3276827 1 89 "1932" "2" 296052 2 89 "1932" "2" 696841 1 end
The desired data
case_id | birth_yr | sex | control_id | drawing |
2 | 1939 | 2 | 2 | 0 |
2 | 1939 | 2 | 376946 | 1 |
2 | 1939 | 2 | 2942780 | 2 |
2 | 1939 | 2 | 47779 | 3 |
Moon Lu
0 Response to Adding new rows for each group set
Post a Comment