Complex reshape

#1
Hello guys,

I really need help with this on. I have a dataset of healthcare organization with the following variables:
ContactID : organization ID
Quarter : data reporting period - first or second quarter
Services : services provide
Clients : how many clients received this services
Hours: How many hours spend in this service

The way my data set is formatted is not the best one, I would like to reshape it. I am attaching an example of how my data is organized and how I would like it. I would really appreciate any help.

Thank you,
MArvin
 
#2
Code:
clear all
set more off

*----- example data -----

input ///
id	str10 quart	str15 serv	client	hours
2	2014q1	empowerment 	95	     760
2	2014q2	empowerment 	181	     1448
2	2014q1	education	    0	      0
2	2014q2	education	    12	      22
2	2014q1	Housing	       34	      44
2	2014q2	Housing	       23	      23
end

list

*----- what you want -----

reshape wide client hours, i(id serv) j(quart) string

list
 
#3
Hey Roberto,

Thanks for the response but I got a error message

"QTR not unique within ContactID RefServ;
there are multiple observations at the same QTR within ContactID RefServ.
Type "reshape error" for a listing of the problem observations."

I really hopw you can help me with this . I am attaching my original dataset.

Thank you very much!

MArvin
 
#4
Your dataset has observations like:

Code:
ContactID	QTR	RefServ	Hours	Clients	
12	2014q1	housing assistance	220.25	197
12	2014q1	housing assistance	78	87	
12	2014q2	housing assistance	110.25	109
Notice repeated QTR (2014q1) for the same ContactID and RefServ. You need to figure out what to do with that before reshaping. A reshape like you say you want in your first post is impossible with observations like those.