In Stata, I would like to be able to bring value labels up into variable labels when reshaping wide.
My raw data looks like this:
patient hosp_id hosp_name charges
Andrew 1 Springfield General $10
Barry 1 Springfield General $20
Crista 2 Lincoln Medical Center $10
Doris 2 Lincoln Medical Center $15
Ellen 1 Springfield General $15
Faye 3 Memorial Hospital $35
I then label the values of hosp_id and reshape wide.
label define hosp_names 1 "Springfield General" 2 "Lincoln Medical Center" 3 "Memorial Hospital"
label value hosp_id hosp_names
reshape wide charges, i(patient) j(hosp_id)
I would like the labels that I placed on hosp_id to follow their associated values and become variable labels. I know that I can label the variables one by one after reshaping, but this may be impractical with a much larger set of j values (in this case hospitals). How can I label each of the hosp_id variables with the associated value of hosp_name programmatically?