In my study 120 observations represent the number of months and the random numbers adding up to 196 represent the number of mergers.
Starting from that, here is code that, I believe, accomplishes the desired goal.
Code:
clear set seed 42 local reps 10 // 1000 local mergers 14 // 196 local months 12 // 120 set obs `reps' generate rep = _n expand `mergers' generate month = runiformint(1,`months') generate N = 1 collapse (sum) N, by(rep month) fillin rep month replace N = 0 if _fillin drop _fillin label variable N . sort rep month list if rep<=2, noobs sepby(rep) tab month N // better to leave the data in a long layout // but if necessary, here is a wide layout rename N r reshape wide r, i(rep) j(month) list if rep<=2, noobs
Code:
. clear . set seed 42 . local reps 10 // 1000 . local mergers 14 // 196 . local months 12 // 120 . . set obs `reps' number of observations (_N) was 0, now 10 . generate rep = _n . . expand `mergers' (130 observations created) . generate month = runiformint(1,`months') . generate N = 1 . . collapse (sum) N, by(rep month) . fillin rep month . replace N = 0 if _fillin (45 real changes made) . drop _fillin . label variable N . . . sort rep month . list if rep<=2, noobs sepby(rep) +-----------------+ | rep month N | |-----------------| | 1 1 1 | | 1 2 4 | | 1 3 2 | | 1 4 0 | | 1 5 0 | | 1 6 0 | | 1 7 1 | | 1 8 2 | | 1 9 1 | | 1 10 0 | | 1 11 2 | | 1 12 1 | |-----------------| | 2 1 2 | | 2 2 0 | | 2 3 1 | | 2 4 1 | | 2 5 1 | | 2 6 1 | | 2 7 1 | | 2 8 2 | | 2 9 1 | | 2 10 1 | | 2 11 0 | | 2 12 3 | +-----------------+ . . tab month N | . month | 0 1 2 3 4 5 | Total -----------+------------------------------------------------------------------+---------- 1 | 6 2 2 0 0 0 | 10 2 | 4 1 2 2 1 0 | 10 3 | 4 5 1 0 0 0 | 10 4 | 5 3 2 0 0 0 | 10 5 | 4 3 1 2 0 0 | 10 6 | 4 1 2 3 0 0 | 10 7 | 2 4 2 1 1 0 | 10 8 | 2 3 3 0 2 0 | 10 9 | 4 5 0 0 0 1 | 10 10 | 4 4 0 1 0 1 | 10 11 | 3 3 3 1 0 0 | 10 12 | 3 3 1 3 0 0 | 10 -----------+------------------------------------------------------------------+---------- Total | 45 37 19 13 4 2 | 120 . . // better to leave the data in a long layout . // but if necessary, here is a wide layout . . rename N r . reshape wide r, i(rep) j(month) (note: j = 1 2 3 4 5 6 7 8 9 10 11 12) Data long -> wide ----------------------------------------------------------------------------- Number of obs. 120 -> 10 Number of variables 3 -> 13 j variable (12 values) month -> (dropped) xij variables: r -> r1 r2 ... r12 ----------------------------------------------------------------------------- . list if rep<=2, noobs +--------------------------------------------------------------------+ | rep r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 | |--------------------------------------------------------------------| | 1 1 4 2 0 0 0 1 2 1 0 2 1 | | 2 2 0 1 1 1 1 1 2 1 1 0 3 | +--------------------------------------------------------------------+ .
Comment