Hello Stata List,
I am working with panel data and preparing it for a mixed logit model using cmxtmixlogit. My dataset includes multiple profession alternatives for each individual in each year, creating a structure where each id in each year has 27 profession alternatives. However, when running the cmxtmixlogit model I encounter the following error: "weights must be the same for all observations of a case."
here is my code (weight variable is : wgt_UB_all, npi stands for Non-pecuniary index)
To troubleshoot, I checked for duplicates and confirmed:
Thank you in advance for your assistance!
I am working with panel data and preparing it for a mixed logit model using cmxtmixlogit. My dataset includes multiple profession alternatives for each individual in each year, creating a structure where each id in each year has 27 profession alternatives. However, when running the cmxtmixlogit model I encounter the following error: "weights must be the same for all observations of a case."
here is my code (weight variable is : wgt_UB_all, npi stands for Non-pecuniary index)
Code:
use "${datain}ct1319_cross.dta", replace
global z_components "z_skills z_autonomy z_support z_stability z_wlbalance z_physical_risk z_psy_risk z_scheduling z_flexibility z_intensity z_ergo"
* Get unique levels of profession2
levelsof profession2, local(professions)
** mean wage and npi in each year by profession
foreach p in `professions' {
foreach var in z_m_ac_npi wage_m wage_h $z_components {
* Summarize z_ac_npi for profession `p` and store the result in a local macro
qui sum `var' if profession2 == `p' & year == 2013, mean
qui gen mean_`var'`p' = r(mean)
qui sum `var' if profession2 == `p' & year == 2019, mean
qui replace mean_`var'`p' = r(mean) if year == 2019
}
}
keep id wage_h wage_m mean_* profession2 year wgt_UB_all dip_cat sexe
reshape long mean_wage_m mean_wage_h mean_z_m_ac_npi mean_z_skills mean_z_autonomy mean_z_support mean_z_stability mean_z_wlbalance mean_z_physical_risk mean_z_psy_risk mean_z_scheduling mean_z_flexibility mean_z_intensity mean_z_ergo, i(year id) j(profession2d)
gen choice = (profession2d == profession2)
g dummy_2019 = (year==2019)
foreach var in z_m_ac_npi $z_components {
cap drop intr_`var'
gen float intr_`var' = mean_`var' * dummy_2019
}
cmset id year profession2d
cmxtmixlogit choice [pw = wgt_UB_all], random(mean_z_m_ac_npi mean_wage_h intr_z_m_ac_npi)
To troubleshoot, I checked for duplicates and confirmed:
- duplicates report _caseid wgt_UB_all shows exactly 27 copies for each _caseid, which aligns with expectations.
- duplicates report year id profession2d shows each combination appears only once..
Thank you in advance for your assistance!
