Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identifying Muslim Drivers

    Dear all,

    I would appreciate if you could share some of your stata knowledge with me.
    I have data about all taxi rides in new york in January 2013.
    Because Muslim drivers pray five times a day, this makes it possible to determine what drivers are Muslim.
    This is where the idea came from: http://www.theiii.org/index.php/997/...-taxi-drivers/

    At first I made a variable called ''working during praying times " with value 0.
    As soon as a drivers had a ride during praying times, I changed this value to 1.
    I did this for all days, five times a day.
    Now I want to make a new dummy column called Muslim with either a 1 or a 0.
    And this is where I could use some guidance.

    There is a variable in each ride that represents a driver.
    Of course some drivers did 'on accident' not work on praying times, I am interested in those that never worked during praying times.
    So how do I make this dummy variable?
    I'm new to stata, so if somebody is willing to help me, the obvious is not always obvious to me.

    Best wishes and thanks in advance,

    Bram.




  • #2
    It would have been easier if you had shown an example of your data so we could know exact variable names. But it seems you have a variable that identifies drivers: I'll call it driver. Then you have this other variable work_during_prayer_time. You want to identify those drivers who never work during prayer time.

    Code:
    by driver, sort: egen ever_work_prayer_time = max(work_during_prayer_time)
    gen never_work_prayer_time = !ever_work_prayer_time

    Comment


    • #3
      Driver work_during_prayer_time ever_work_prayer_time
      A 0
      B 1
      A 0
      B 0
      Thanks for your guidance Clyde,

      I understand the way you could potentially tackle my problem by this method, yet I didn't work out. the maximum was at max 1 whereas this could be in the hundreds since a driver makes hundreds a ride each month.
      Could you perhaps take a look at it again? I have given an example to make it bit easier to understand.

      In this small example, driver B has worked once during prayer time, so he is not a Muslim. Driver A has never worked during prayer time, so he is a Muslim.
      Now I want to have this 3rd column to have a dummy variable. This should be 0 for driver A and 1 for driver B..

      Again, any help I would appreciate a lot.

      Best wishes,

      Bram
      Last edited by Bram Heitinga; 15 Apr 2017, 15:53.

      Comment


      • #4
        Please take a look whether this is what you wish:

        Code:
        . input str2 driver work_prayer
        
                driver  work_pr~r
          1. A 0
          2. B 1
          3. A 0
          4. B 0
          5. end
        
        . by driver, sort: egen ever_work_prayer_time = total(work)
        
        . by driver, sort: gen muslim = ever_work_prayer_time==0
        
        . list
        
             +---------------------------------------+
             | driver   work_p~r   ever_w~e   muslim |
             |---------------------------------------|
          1. |      A          0          0        1 |
          2. |      A          0          0        1 |
          3. |      B          0          1        0 |
          4. |      B          1          1        0 |
             +---------------------------------------+
        Best regards,

        Marcos

        Comment


        • #5
          Marcos,

          This is exactly what I wish!

          Best wishes,

          Bram

          Comment


          • #6
            Bram,

            I'm confused. I'm happy that Marcos' code has worked for you, but it produces the same result as mine (I just called my variable never_worked_prayer_time instead of muslim), So I don't understand what didn't work about mine. Can you explain?

            Comment


            • #7
              Hello Clyde,

              I understand your confusion, I am a bit confused as well. But since I'm new at stata, it probably is a mistake of me somewhere down the line. I'll reproduce the situation and test your solution once more and see if this time it does work. Thanks for support, and Marcos thank you as well.

              Best regards, Bram.

              Comment


              • #8
                Okay Clyde,

                I can confirm that your method works as well. I'm sorry for the confusion but I wanted to let you know.

                All the best,

                Bram.

                Comment


                • #9
                  Hello Bram, I'm glad you consider your query appropriately solved.

                  Dear Clyde, I confess I didn't check your command. I just read Bram's comment, declaring the command had not given what he wished. In spite of being on a trip, I 'jumped' into the laptop and tried to provide the command. Had I taken the time to look carefully, I would surely have noticed your command gives similar results.

                  Anyway, that was a great opportunity to realize I must be following the right track, having much learned from you.
                  Best regards,

                  Marcos

                  Comment


                  • #10
                    Dear Marcos and Clyde,

                    My research is doing great, however I could use some help (again).
                    Thanks to your input I am able to identify those drivers that have never worked during prayer time.
                    However to do some robustness checks, I also need to gain insight in how many people have only worked a couple of times during praying times.
                    Basicly I need to create a count function that counts how many times a driver has worked during prayer times.

                    Then I would like to have a graph that shows how many drivers missed not a single prayer, up untill how many people worked during perhaps all prayers.
                    I would be grateful if you could enlighten me.
                    Best wishes, Bram

                    Comment

                    Working...
                    X