Many thanks Mike,
In the code you proposed, the variable "batch" has the same value for the whole dataset, which in this case is 7. Hence, all obs are deleted in the loop when we keep observations from the dataset where batch = 1, ..., 6, 8, 9, 10.
In the code you proposed, the variable "batch" has the same value for the whole dataset, which in this case is 7. Hence, all obs are deleted in the loop when we keep observations from the dataset where batch = 1, ..., 6, 8, 9, 10.
Code:
. gen byte batch = 1 + mod(_N,10) . tab batch batch | Freq. Percent Cum. ------------+----------------------------------- 7 | 12,033,366 100.00 100.00 ------------+----------------------------------- Total | 12,033,366 100.00 . display _N 12033366 . preserve . . forval i = 1/10 { 2. . keep if (batch == `i') 3. . joinby alter_id using colleagues.dta 4. . save batch`i' 5. . restore 6. . } (12,033,366 observations deleted)
Comment