clear // set up data set obs 4 generate x1 = trunc((_n+1)/2) generate x2 = mod(_n, 2)+1 generate count0 = 50 generate count1 = 75 if x1==2 replace count1 = 25 if x1==1 tab x1 x2 [fw=count0] // reference table tab x1 x2 [fw=count1] // "sample" table // calculate each cell's contribution to chi-square generate chipart = (count1-count0)^2/count0 // then sum and compare to a chi-square distribution with 3 df quietly summarize chipart display r(sum) display chi2(r(sum), 3) // very small probability of a value this big