Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Flaggin Changes in Data


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Flaggin Changes in Data
Date   Tue, 2 Jul 2013 10:14:20 +0100

I would use a composite string to hold information on rooms booked on
a given day to a given person.

bysort id date : gen rooms = string(room[1])
by id date : replace rooms = rooms[_n-1] + " " + string(room) if _n > 1
by id date: replace rooms = rooms[_N]

Then your flag is

by id : gen flag = rooms != rooms[_n-1] & date != date[_n-1] & date != date[1]

That may not catch all you want, but it might help.
Nick
njcoxstata@gmail.com


On 2 July 2013 08:31, Beatrice Benavidez <beatricestata1711@gmail.com> wrote:
> Hi everyone,
>
> I have hotel occupancy data of individuals who change rooms in the
> hotel in the following format:
>
> Booking ID            Date           Room
> 17                        1/1/2013      3
> 17                        1/1/2013      4
> 17                        2/1/2013      5
> 17                        2/1/2013      6
> 27                        1/1/2013      10
> 27                        1/1/2013      11
> 27                        2/1/2013      12
> 37                        1/1/2013      10
> 37                        2/1/2013      11
> 37                        2/1/2013      12
>
> I would like to flag the bookingid rooms that changed with
> 'Flag_rmchange' variable:
>
> Booking ID            Date           Room               Flag_rmchange
> 17                        1/1/2013      3
> 17                        1/1/2013      4
> 17                        2/1/2013      5                      1
> 17                        2/1/2013      6                      1
> 27                        1/1/2013      10
> 27                        1/1/2013      11
> 27                        2/1/2013      12                    1
> 37                        1/1/2013      10
> 37                        2/1/2013      11                    1
> 37                        2/1/2013      12
>
> What happened here is that I flagged bookingid rooms that were changed
> from the day before. I make the flags always on the day after, see
> here the flags are on 2/1. Problem is I don't know which room they
> changed from the day before to the next but it shouldn't matter as I
> just need to flag that did change rooms.
>
> I would like to find a way to automatically flag the bookingid rooms
> that were changed like the above, where the room they change from is
> different to the room they change to, the next day.
>
> With booking Id 17, there were two different rooms on 1/1 and two
> different rooms on 2/1 so the should be two flags on 2/1. But with
> booking id 27, person stayed in two rooms on 1/1 but one room on 2/1
> so the flag is on 2/1 for room 12. However, with booking id 37, person
> stayed in 1 room on 1/1 but two rooms on 2/1 so the flag should be
> assigned to one room 2/1 as person only changed room once. I assigned
> it to room 11. However, it doesn't matter if i had assigned it to
> either room 11 or room 12 as long as there is one flag.
>
> So maybe, a script can be developed where there is the same number of
> rooms from one day to the next with completely different room numbers,
> which means they were room changes so should be flagged.
>
> Any suggestions would be very helpful!
>
> Kind regards,
>
>
> Beatrice
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index