Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replicating tabulate intersection with analytic weights

    Dear Statalisters,

    I am trying to estimate the intersect of mothers an low educated individuals without using the 'tabulate' command in a dataset with weights in Stata v. 16.1.
    The two categories are represented by dummy variables in the dataset (mother and low_educ, respectively).
    If I were to use 'tabulate', I'd write something like this:

    Code:
     tab mother low_educ [aw = weight]
    I ran this code for reference and the intersect (where both dummies == 1) has 742.41172 weighted observations.

    I read the section of the manual on analytic weights and got close to some solution but I think I am missing something regarding how Stata handles weights.

    My attempt:
    Code:
    // Rescale weights to sum to N
    egen total_weight = sum(weight)
    gen num_obs = _N
    gen weight_2 = weight / total_weight * num_obs
    
    // Apply weights
    gen mother_w2 = mother*weight_2
    gen low_educ_w2 = low_educ*weight_2
    
    // Create table with intersect
    mkmat mother_w2 low_educ_w2, matrix(D)
    mat define DD= D' *D
    mat list DD
    I get 1087.4816 instead of 742.41172 as the number of weighted observations in the intersect.

    What should I write differently to get the same result?

    Thank you for your help in advance.

    Balu
    Last edited by Balazs Munkacsy; 03 Jul 2024, 07:17.
Working...
X