Code:
. reshape wide `to_fix', i(id p_id wave) j(hgsex) variable hgsex contains missing values r(498);
As I have a large number of variables, I thought this may cause an issue, but even after testing this theory by reducing the number of variables in my list, the same error occurred.
In the Stata output below, I observe two potential issues: (1) the high number of missing values for the gender variable, and (2) there appears an issue in the "reshape long" line, where, (in the output) "adhi" is added to p_and q_ prefixes but as you can see this is not in my code.
Note that the panel data I am using includes data for respondents (no prefix to variables) and their partners (variables are identified with a "p_" prefix).
Code:
. drop if missing(hgsex, p_hgsex) (187,863 observations deleted) . local to_fix hgage religb relat relimp mrcurr ordfnum mrn esbrd edhigh1 edsstyp cety01 tchave tchad tcr tcyng /// > Socio-eocn > fmlwop hhsos anengf ancobn gh1 lssupvl pdsad losat lsclubn lstrust lshrvol lsvol lsnwmc lefrd lefnw lefni // . rename (hgsex `to_fix') q_= . local newvars: subinstr local to_fix " " " @", all . local newvars @`newvars' . . reshape long @hgsex `newvars', i(id p_id wave) j(_j) string (note: j = p_ p_edhi q_ q_edhi) (note: p_edhihgsex not found) (note: p_edhihgage not found) (note: p_edhireligb not found) (note: p_edhirelat not found) (note: p_edhirelimp not found) (note: p_edhimrcurr not found) (note: p_edhiordfnum not found) (note: p_edhimrn not found) (note: p_edhiesbrd not found) (note: p_edhiedhigh1 not found) (note: p_edhiedsstyp not found) (note: p_edhicety01 not found) (note: p_edhitchave not found) (note: p_edhitchad not found) (note: p_edhitcr not found) (note: p_edhitcyng not found) (note: p_edhifmlwop not found) (note: p_edhihhsos not found) (note: p_edhianengf not found) (note: p_edhiancobn not found) (note: p_edhilssupvl not found) (note: p_edhipdsad not found) (note: p_edhilosat not found) (note: p_edhilsclubn not found) (note: p_edhilstrust not found) (note: p_edhilshrvol not found) (note: p_edhilsvol not found) (note: p_edhilsnwmc not found) (note: p_edhilefrd not found) (note: p_edhilefnw not found) (note: p_edhilefni not found) (note: q_edhihgsex not found) (note: q_edhihgage not found) (note: q_edhireligb not found) (note: q_edhirelat not found) (note: q_edhirelimp not found) (note: q_edhimrcurr not found) (note: q_edhiordfnum not found) (note: q_edhimrn not found) (note: q_edhiesbrd not found) (note: q_edhiedhigh1 not found) (note: q_edhiedsstyp not found) (note: q_edhicety01 not found) (note: q_edhitchave not found) (note: q_edhitchad not found) (note: q_edhitcr not found) (note: q_edhitcyng not found) (note: q_edhifmlwop not found) (note: q_edhihhsos not found) (note: q_edhianengf not found) (note: q_edhiancobn not found) (note: q_edhilssupvl not found) (note: q_edhipdsad not found) (note: q_edhilosat not found) (note: q_edhilsclubn not found) (note: q_edhilstrust not found) (note: q_edhilshrvol not found) (note: q_edhilsvol not found) (note: q_edhilsnwmc not found) (note: q_edhilefrd not found) (note: q_edhilefnw not found) (note: q_edhilefni not found) Data wide -> long ----------------------------------------------------------------------------- Number of obs. 87309 -> 349236 Number of variables 479 -> 448 j variable (4 values) -> _j xij variables: p_hgsex p_edhihgsex ... q_edhihgsex -> hgsex p_hgage p_edhihgage ... q_edhihgage -> hgage p_religb p_edhireligb ... q_edhireligb -> religb p_relat p_edhirelat ... q_edhirelat -> relat p_relimp p_edhirelimp ... q_edhirelimp -> relimp p_mrcurr p_edhimrcurr ... q_edhimrcurr -> mrcurr p_ordfnum p_edhiordfnum ... q_edhiordfnum -> ordfnum p_mrn p_edhimrn ... q_edhimrn -> mrn p_esbrd p_edhiesbrd ... q_edhiesbrd -> esbrd p_edhigh1 p_edhiedhigh1 ... q_edhiedhigh1 -> edhigh1 p_edsstyp p_edhiedsstyp ... q_edhiedsstyp -> edsstyp p_cety01 p_edhicety01 ... q_edhicety01 -> cety01 p_tchave p_edhitchave ... q_edhitchave -> tchave p_tchad p_edhitchad ... q_edhitchad -> tchad p_tcr p_edhitcr ... q_edhitcr -> tcr p_tcyng p_edhitcyng ... q_edhitcyng -> tcyng p_fmlwop p_edhifmlwop ... q_edhifmlwop -> fmlwop p_hhsos p_edhihhsos ... q_edhihhsos -> hhsos p_anengf p_edhianengf ... q_edhianengf -> anengf p_ancobn p_edhiancobn ... q_edhiancobn -> ancobn p_gh1 p_edhigh1 ... q_edhigh1 -> gh1 p_lssupvl p_edhilssupvl ... q_edhilssupvl -> lssupvl p_pdsad p_edhipdsad ... q_edhipdsad -> pdsad p_losat p_edhilosat ... q_edhilosat -> losat p_lsclubn p_edhilsclubn ... q_edhilsclubn -> lsclubn p_lstrust p_edhilstrust ... q_edhilstrust -> lstrust p_lshrvol p_edhilshrvol ... q_edhilshrvol -> lshrvol p_lsvol p_edhilsvol ... q_edhilsvol -> lsvol p_lsnwmc p_edhilsnwmc ... q_edhilsnwmc -> lsnwmc p_lefrd p_edhilefrd ... q_edhilefrd -> lefrd p_lefnw p_edhilefnw ... q_edhilefnw -> lefnw p_lefni p_edhilefni ... q_edhilefni -> lefni ----------------------------------------------------------------------------- . drop _j . reshape wide `to_fix', i(id p_id wave) j(hgsex) variable hgsex contains missing values r(498);
I thought the error may be visible in my code. I'm happy to provide a data example if needed.
Stata v15.1. Note: previously posted in an old post, but decided it did not fit with the subject line of that post.
0 Response to Using -reshape- to create male/female versions of key variables
Post a Comment