Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Need help with combing observations by using by: command along with subscripting


From   Rebecca Pope <rebecca.a.pope@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Need help with combing observations by using by: command along with subscripting
Date   Wed, 6 Feb 2013 11:44:40 -0600

Mike,
The way you have specified the -bysort- currently, Stata is looking
within the patient and date of birth for multiple records. You just
want it to look within patient only.

bys PATIENTno (dtbirth): replace medicalrecordnumber =
medicalrecordnumber[1] if missing(medicalrecordnumber)

The underlying assumption is that an MRN will always be present when
the DOB is present. If not, you might be better off creating a look-up
table of MRNs and using -merge- to update your missing values.

preserve
keep PATIENTno medicalrecordnumber
keep if !missing(medicalrecordnumber)
duplicates drop
tempfile mrn
save `"`mrn'"'
restore
merge m:1 PATIENTno using `"`mrn'"', update

* warning: code not tested

Cheers,
Rebecca

On Wed, Feb 6, 2013 at 11:12 AM, Michael Stewart
<michaelstewartresearch@gmail.com> wrote:
> Hi,
>
> I need help with following data where I am trying to combine
> observations for each patient
>
> PATIENTno   dtbirth       medicalrecordnumber   accountnumber
>     1             8/10/1907         1111111
>     1              .                                                        dddddddd
>    2             12/14/1910        222222222
>    2                 .                                                       eeeeee
>    3              4/16/1914         33333333                  rrrrrrr
>
>
> PATIENTno,medicalrecordnumber & accountnumber -->STRING format
>
> dtbirth-->%td format
>
>
> I need to combine row one and row two for patient 1 so that resultatnt
> row will have information from both rows one and row two
>
> I tried to use subscripting as follows
>
> bysort PATIENTno dtbirth: repalce medicalrecordnumber= medicalrecordnumber[_n-1]
>
> then all values for the medicalrecordnumber are turning to blank spaces
>
> I also tried bysort PATIENTno dtbirth: repalce medicalrecordnumber=
> medicalrecordnumber[1] but it didnt work either.
>
> Can you please help.
>
> --
> Thank you ,
> Yours Sincerely,
> Mike.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/



On Wed, Feb 6, 2013 at 11:12 AM, Michael Stewart
<michaelstewartresearch@gmail.com> wrote:
> Hi,
>
> I need help with following data where I am trying to combine
> observations for each patient
>
> PATIENTno   dtbirth       medicalrecordnumber   accountnumber
>     1             8/10/1907         1111111
>     1              .                                                        dddddddd
>    2             12/14/1910        222222222
>    2                 .                                                       eeeeee
>    3              4/16/1914         33333333                  rrrrrrr
>
>
> PATIENTno,medicalrecordnumber & accountnumber -->STRING format
>
> dtbirth-->%td format
>
>
> I need to combine row one and row two for patient 1 so that resultatnt
> row will have information from both rows one and row two
>
> I tried to use subscripting as follows
>
> bysort PATIENTno dtbirth: repalce medicalrecordnumber= medicalrecordnumber[_n-1]
>
> then all values for the medicalrecordnumber are turning to blank spaces
>
> I also tried bysort PATIENTno dtbirth: repalce medicalrecordnumber=
> medicalrecordnumber[1] but it didnt work either.
>
> Can you please help.
>
> --
> Thank you ,
> Yours Sincerely,
> Mike.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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