Announcement

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

  • Help: weights not allowed r(101)

    Hi! I met a mistake in following command:

    egen x2 = group(sex re age educ)

    gen wm = sex == 1 & re == 1

    egen wminc = mean(incwage) [pw=x2] if wm == 1, by(age)

    First two lines worked and the mistake reported at the third line: weights not allowed r(101)

    Could you please help me solve it ?

  • #2
    The -egen- command does not provide for the use of weights. You can determine if a Stata command does allow weights by the presence of [weight] in the syntax diagram shown in the -help- for that command. -help egen- shows a syntax diagram without [weight]. To accomplish what I presume you want, and assuming that x2 is a probability weight variable whose values sum to 1.0 within each group, you could do this:
    Code:
    egen wminc = total(incwage * x2) if wm == 1, by(age)
    (Just as I posted I noticed that the way your x2 variable was constructed it almost certainly is not a probability weight variable, so you must have had something else in mind.)
    Last edited by Mike Lacy; 25 Nov 2022, 21:24. Reason: Corrected my oversight of what the x2 variable is.

    Comment


    • #3
      Thank you for your reply! My third line code should be
      Code:
      egen wminc = mean(incwage) if wm == 1 [pw=x2], by(age)

      (and my purpose is to calculate average income by age for each group controlling for age and education)

      And it seems not work under egen.

      Oh, I solved it by using gegen after installing gtools. And yes, x2 is a probability weight and I made a mistake gen x2 = perwt/p2.

      Thank you again!
      Last edited by Liam Liang; 25 Nov 2022, 22:07.

      Comment

      Working...
      X