XTREG error: weight must be constant within pidp
As I mentioned in a separate issue weeks ago, I am analysing life satisfaction and GHQ (using indresp files) from 18 waves of the BHPS plus 8 waves of the UKHLS for a total of 16 waves. I have been referring to indin91_lw as the longitudinal weight. My problem/issue is that I have told Stata that the data has a panel structure via xtreg pidp wave. I wish to run: xtreg y x1 x2 [pw=indin91_lw], fe but I keep getting the error, "weight must be constant within pidp". What is the easiest workaround that I can implement for this analysis?
Thanks so much!
#1 Updated by Alita Nandi 3 months ago
- Private changed from Yes to No
- % Done changed from 0 to 50
- Assignee changed from Olena Kaminska to Abigail Dumalus
You need to take i_indin91_lw (as Wave 9 is the last wave you are including) and then attach that to all prior waves, as this weight accounts for non-response and attrition across the waves until UKHLS Wave 9. The reason you are getting this error message is that the value of the weight variable changes within person. So, if you use i_indin91_lw for all waves, the value of the weight variable will not change within person and you will not get an error message.
#2 Updated by Abigail Dumalus 3 months ago
I understand what you’re saying. but is there an extra step or specific code that I need to implement this attachment to all prior waves?I keep going in circles with using this weighting variable with the xtreg command on Stata. It works with other commands but not with xtreg regressions. Kindly advise. Thanks so much!
#3 Updated by Alita Nandi 2 months ago
Let's say your long file is, long.dta. Then you do this:
use long, clear
merge m:1 pidp using i_indresp, keepus(i_indin91_lw) nogen keep(3)
Is this clearer? If not, I could set up an online meeting with you, me and Olena. If you would like that, I will contact you via our usersupport email.
#5 Updated by Abigail Dumalus 2 months ago
I apologise for not replying for almost a week. I have been ill. I currently have several weighting variables in the longitudinal dataset when I merged all indresp files from all 18 BHPS waves and waves 2-9 of the UKHLS. Would it help that I drop all of these current weighting variables and then merge as you have specified above? Or do I keep indin91_lw variable behind then run the xtreg command with this particular weighting variable? As I understand from what you are saying, the xtreg error (weight must be constant within pidp) is happening because the longitudinal dataset currently has all the weighting variables from merging all waves. Am I correct in this understanding?