Announcement

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

  • How to create graphs and generate variables (debugging)

    I am trying to create some graphs using data from a csv file that has all the information about each emergency call's date, response time, call type, priority etc.

    1. we want to create a graph for call volume by year/month etc. However, we are struggling to visualize how the call volume variable should be created, since it's basically counting horizontal data entry (1 call = 1 entry) besides the ones with police on scene.

    2. we are trying to create a graph with month on the x axis, and each month having 4 bars each representing a different call time per that month (morning, afternoon, evening, night) so it will be a very busy graph. The y axis will be call volume of each call time. However, I tried both categorical and dummy variables and none seem to be working. How should we approach this?

    **7.Create dummy variables to indicate time of day call was received
    gen nightcall = 1 if callreceivedtime<= 60000
    //(624840 missing values generated)
    replace night = 0 if night==.
    //(624840 missing values generated)

    gen morningcall = 1 if callreceivedtime<= 120000 & callreceivedtime > 60000
    //(540971 missing values generated)
    replace morning = 0 if morning==.
    //(540971 real changes made)

    gen afternooncall = 2 if callreceivedtime<= 180000 & callreceivedtime > 120000
    //(482467 missing values generated)
    replace afternoon = 0 if afternoon==.
    //(482467 real changes made)

    gen eveningcall = 1 if callreceivedtime> 180000
    //(512409 missing values generated)
    replace evening = 0 if evening==.
    //(512409 real changes made)

    --------------
    **8.Create categorical variable to indicate time of day call was received
    gen calltime = night if callreceivedtime<= 60000
    //(398172 missing values generated)
    replace calltime = morning if callreceivedtime<= 120000 & callreceivedtime > 60000
    //(111392 real changes made)
    replace calltime = afternoon if callreceivedtime<= 180000 & callreceivedtime > 120000
    //(149411 real changes made)
    replace calltime = night if callreceivedtime> 180000
    //(137369 real changes made)


    3. When trying to replicate

    graph bar (priority) totalresponsetime, over(month)

    for the 4 individual response times, some of our graphs turn out to have negative values. Such as

    graph bar (mean) dispatchtoenroute, over(month)

    which produced some bars on both sides of the x axis. Logically, shouldn't that be impossible?

  • #2
    Chloe,

    Welcome to Statalist. Following the advice given in the FAQs all are asked to read when they join tends to increase the likelihood of responses. In particular, with a problem like yours, people will have a hard time helping formulate a solution if they don't have some sample data.

    You don't say how many months of data you have but if you have more than a few, I agree that your graph will be pretty busy--potentially too busy to provide any utility. Is there a reason why you need to use bar graphs by month? It seems that it might be more efficient to create a line graph with a separate line for the volume of calls at each time of day. I also think it would ultimately be easier for someone to understand the data if presented this way.

    Lance

    Comment


    • #3
      Lance gives excellent advice. As a first step, I use CODE delimiters to show what you gave, but itself edited to simpler code and adding some comments and questions.

      Most bizarre of all, none of the code you give has any bearing on your graph call

      Code:
      graph bar (priority) totalresponsetime, over(month)
      as none of the variables mentioned in that statement are mentioned previously.

      Code:
      gen nightcall = callreceivedtime<= 60000
      
      * this can be removed, but note the assumption that -night- implies -nightcall- 
      * potential bug 
      * replace night = 0 if night==.  
      
      gen morningcall = callreceivedtime<= 120000 & callreceivedtime > 60000
      
      * this can be removed, but note the assumption that -morning- implies -morningcall- 
      * potential bug 
      * replace morning = 0 if morning==.
      
      
      gen afternooncall = 2 if callreceivedtime<= 180000 & callreceivedtime > 120000
      * note the assumption that -afternoon- implies -afternooncall- 
      replace afternoon = 0 if afternoon==.
      * ??? why is this variable {0, 2} when others similar all {0,1} 
      
      
      gen eveningcall = callreceivedtime> 180000
      * this will include all the missings too! 
      * this can be removed, but note the assumption that -evening- implies -eveningcall- 
      * potential bug 
      * replace evening = 0 if evening==.
      
      * !!! this just leaves all calls 1, except for afternoon calls 2; unlikely to be what you want from this 
      gen calltime = night if callreceivedtime<= 60000
      replace calltime = morning if callreceivedtime<= 120000 & callreceivedtime > 60000
      replace calltime = afternoon if callreceivedtime<= 180000 & callreceivedtime > 120000
      replace calltime = night if callreceivedtime> 180000
      
      
      
      graph bar (priority) totalresponsetime, over(month)

      Comment

      Working...
      X