Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: using reshape command


From   Niels Schenk <niels@oudwijk.cistron.nl>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: using reshape command
Date   Thu, 09 Oct 2008 18:51:48 +0200

You shouldn't use edate as a stubname, it will suffix your variables with values of edate. This should do it, although it doesn't handle ties of edate within ids, not sure if that's a problem though:

generate edate = date(exam_date, "mdy")       /* change string variable to numeric variable */

drop exam_date

bys id (edate): gen stub = _n // ygives control over which exam comes first, equal edates within id are of arbitrary order though, you could add another sorting variable

reshape wide exam_name exam_score edate exam_outcome, i(id) j(stub)

cheers

Niels


Patrick Mason wrote:
Dear all:
I'm looking for some assistance in using the "reshape" command. I've attached a small sample of the actual data. This is a text file, created by excel.
There are 5 variables: identification, exam_name, exam_date, exam_outcome, and exam_score. Some obervations have the same idnumber, since an individual may have taken more than one examination or may have taken the examination mutiple times (e.g., failing the first time and passing the second or third time). I want to merge this file with another and use the examination score in a regression. Is there some way to use the "reshape" command (or another procedure) to create one observation per identification? For example, if the individual has taken 5 specialty examinations I'd like to create an observation that looks the following: idnumber exam_name1 exam_date1 exam_outcome1 exam_score1 exam_name2 exam_date2 exam_outcome2 exam_score2 ...
Here's what I've tried (and the error message).

generate edate = date(exam_date, "mdy")       /* change string variable to numeric variable */

drop exam_date

reshape wide exam_score, i(identification) j(edate)
(note: j = 14715 14827 14911 14995 15086 15184 15359 15450 15548 15639 15730 15912)
edate not unique within identification; there are multiple observations at the same edate within identification.
Type "reshape error" for a listing of the problem observations.
r(9);

Thanks for your assistance.

-plm





*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index