Statalist


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

Re: st: Reshape-Like Question


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Reshape-Like Question
Date   Tue, 3 Mar 2009 19:18:29 -0600

clear
input pid   str4 site str9 datestamp bglevel str9 enrolldate str9 fuploaddate
1424  "PBCI" "10jan2006" 253     "09jan2006"  "13jan2006"
1424  "PBCI" "10jan2006" 185     "09jan2006"  "13jan2006"
1424  "PBCI" "10jan2006" 252     "09jan2006"  "13jan2006"
1424  "PBCI" "13jan2006" 223     "09jan2006"  "13jan2006"
1424  "PBCI" "13jan2006" 173     "09jan2006"  "13jan2006"
1424  "PBCI" "13jan2006" 156     "09jan2006"  "13jan2006"
1428  "PBCI" "10jan2006" 208     "11jan2006"  "11jan2006"
1428  "PBCI" "10jan2006" 226     "11jan2006"  "11jan2006"
1428  "PBCI" "10jan2006" 242     "11jan2006"  "11jan2006"
1428  "PBCI" "10jan2006" 279     "11jan2006"  "11jan2006"
1428  "PBCI" "11jan2006" 222     "11jan2006"  "11jan2006"
1428  "PBCI" "11jan2006" 184     "11jan2006"  "11jan2006"
1428  "PBCI" "11jan2006" 204     "11jan2006"  "11jan2006"
end

bys pid date: gen id = _n
reshape wide bg , i(pid date  ) j(  id)
l, sepby(pid)


Scott

On Tue, Mar 3, 2009 at 6:05 PM, Alan Neustadtl <[email protected]> wrote:
>
> I am using Stata V10 and have a dataset with repeated blood glucose
> measurements per day.  The data are ordered by patient id (pid) and
> within patients by the date of the glucose readings (datestamp).  In
> other words, there is one record per patient/blood glucose reading.
>
> I would like a new dataset with one record per patient id/date but
> with one variable for each reading that day.  For example, in a month
> with thirty days where a patient took at least one blood glucose
> measurement per day, there would be thirty records.  There would be a
> variable corresponding to each blood glucose measurement.
>
> The following data indicate what I currently have and what I would
> like to have.  I have put a blank line between groups to make the data
> more readable but these breaks do not exist in the Stata dataset.
>
> This strikes me as a -reshape- problem but the dates are duplicates so
> -reshape- fails.  If this is not a reshape problem I don't even know
> what to call it to search the Statalist archives.
>
> Any suggestions/pointers are welcome.
>
>
> ORIGINAL DATA
> pid   site datestamp bglevel enrolldate fuploaddate
> 1424  PBCI 10jan2006 253     09jan2006  13jan2006
> 1424  PBCI 10jan2006 185     09jan2006  13jan2006
> 1424  PBCI 10jan2006 252     09jan2006  13jan2006
>
> 1424  PBCI 13jan2006 223     09jan2006  13jan2006
> 1424  PBCI 13jan2006 173     09jan2006  13jan2006
> 1424  PBCI 13jan2006 156     09jan2006  13jan2006
>
> 1428  PBCI 10jan2006 208     11jan2006  11jan2006
> 1428  PBCI 10jan2006 226     11jan2006  11jan2006
> 1428  PBCI 10jan2006 242     11jan2006  11jan2006
> 1428  PBCI 10jan2006 279     11jan2006  11jan2006
>
> 1428  PBCI 11jan2006 222     11jan2006  11jan2006
> 1428  PBCI 11jan2006 184     11jan2006  11jan2006
> 1428  PBCI 11jan2006 204     11jan2006  11jan2006
>
>
> NEWLY SHAPED DATA
> pid   site datestamp enrolldate fuploaddate bg1 bg2 bg3 bg4
> 1424  PBCI 10jan2006 09jan2006  13jan2006   253 185 252   .
> 1424  PBCI 13jan2006 09jan2006  13jan2006   223 173 156   .
>
> 1428  PBCI 10jan2006 11jan2006  11jan2006   208 226 242 279
> 1428  PBCI 11jan2006 11jan2006  11jan2006   222 184 204   .
>
> Thanks,
> Alan

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index