I'm currently doing some research on paid parking in 3 parking garages
The stata-version I am using is 14.1.
The data runs from 1 januari 2014 up till 31 december 2016. I have rougly 4.5 million observations.
I would like to create a dataset that shows how many cars are parked on each hour of the day (for each day of the dataset), by garage.
Using stata is relatively new to me, but after some long hours of trying myself, I still have some problems creating this dataset.
-The problem-
I want to count the number of cars parked within a one hour interval. However, the cars are often parked for a longer time period than one hour, so they should be counted for multiple hours of the day. When running my code (see below), everything seems to be like I want it to be, however the number of cars at a given hour regularly exceeds the maximum capacity of the garage (for 'centraal' it is 1050).
Is there something wrong with my code that causes the program to count 1 car multiple times in 1 hour, or does my code not make sense at all?
-The data-
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str8 garage_nm double(start_parking end_parking) float parkingtime_hours "Centraal" 1704153965000 1704158160000 1.1652777 "Centraal" 1704155760000 1704162842000 1.9672222 "Centraal" 1704155829000 1704171787000 4.432778 "Centraal" 1704156183000 1704169860000 3.799167 "Centraal" 1704156427000 1704175203000 5.215556 "Centraal" 1704156605000 1704171420000 4.115278 "Centraal" 1704156780000 1704168784000 3.3344445 "Centraal" 1704156967000 1704185347000 7.883333 "Centraal" 1704157020000 1704166507000 2.635278 "Centraal" 1704157082000 1704175622000 5.15 "Centraal" 1704157140000 1704161589000 1.2358333 "Centraal" 1704157205000 1704171661000 4.0155554 "Centraal" 1704157261000 1704176469000 5.335556 "Centraal" 1704157326000 1704160861000 .9819444 "Centraal" 1704157441000 1704171240000 3.8330555 "Centraal" 1704157509000 1704162969000 1.5166667 "Centraal" 1704157565000 1704169623000 3.3494444 "Centraal" 1704157684000 1704167528000 2.7344444 "Centraal" 1704157684000 1704167522000 2.732778 "Centraal" 1704157807000 1704170887000 3.6333334 end format %tc start_parking format %tc end_parking
I've done the following myself
-the code-
Code:
gen id=_n expand parkingtime_hours, gen(copies) bysort id: gen hr = _n - 1 gen double datetime = start_parking + hr*60*60*1000 format datetime %tc gen date = dofc(datetime) gen hrs = hh(datetime) gen cars = 1 collapse (sum) cars, by(garage_nm date hrs) format date %td
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str8 garage_nm float(date hrs) double cars "Centraal" 19724 0 22 "Centraal" 19724 1 70 "Centraal" 19724 2 90 "Centraal" 19724 3 70 "Centraal" 19724 4 46 "Centraal" 19724 5 30 "Centraal" 19724 6 48 "Centraal" 19724 7 70 "Centraal" 19724 8 78 "Centraal" 19724 9 80 "Centraal" 19724 10 84 "Centraal" 19724 11 88 "Centraal" 19724 12 102 "Centraal" 19724 13 94 "Centraal" 19724 14 108 "Centraal" 19724 15 118 "Centraal" 19724 16 146 "Centraal" 19724 17 186 "Centraal" 19724 18 188 "Centraal" 19724 19 182 "Centraal" 19724 20 162 "Centraal" 19724 21 142 "Centraal" 19724 22 124 "Centraal" 19724 23 96 "Centraal" 19725 0 64 "Centraal" 19725 1 48 "Centraal" 19725 2 46 "Centraal" 19725 3 46 "Centraal" 19725 4 58 "Centraal" 19725 5 90 "Centraal" 19725 6 146 "Centraal" 19725 7 266 "Centraal" 19725 8 438 "Centraal" 19725 9 578 "Centraal" 19725 10 720 "Centraal" 19725 11 898 "Centraal" 19725 12 1004 "Centraal" 19725 13 1084 "Centraal" 19725 14 1224 "Centraal" 19725 15 1112 "Centraal" 19725 16 810 "Centraal" 19725 17 598 "Centraal" 19725 18 602 "Centraal" 19725 19 536 "Centraal" 19725 20 418 "Centraal" 19725 21 300 "Centraal" 19725 22 212 "Centraal" 19725 23 154 "Centraal" 19726 0 112 "Centraal" 19726 1 96 end format %td date
0 Response to Counting observations within a particular time-interval
Post a Comment