I have been trying to form a query in MMA11 for data for all counties in the US. Apparently, one must first acquire a list of the states and territories, use that to query for counties, and then use the full list of county entities in the final query for data. I try this in the attached notebook.
As in the documentation example, AdministrativeDivisionData can be used to get a list of the counties in a state entity, where the state entity can be entered with freeform input. It seems reasonable then that the states and territories could be gotten the same way by calling AdministrativeDivisionData with the United States (as freeform) used in place of the state name. But it seems that the data system does not believe that the United States country entity has administrative subdivisions.
Can someone please give me a clue as to how this can be done? For example, determine the median income for all counties in the US?
Based on this link (), I have been avoiding the XXXData[] objects in favor of the EntityXXX[] classes. If this is the approach you have to take with Entity[]s, maybe their design is not suited for problems like this. Of course, doing this with SQL is trivial
There are some challenges to accomplish what you are seeking. I hope that the method below is either not the most efficient and/or it will be improved going forward.
I did not try the approach of downloading all of the (hundred thousand plus) administrative divisions. Based on some examples, I did the following:
asked W|a for a list of states
fed this list into Interpreter[] to get the state Enitity[]s
fed the list of states back into W|a to get a list of counties, for each state
fed this list into Interpreter[] to get the county Enitity[]s <<< there are problems with this (i.e. Hamilton County, Ohio was returned by Interpreter[])
got the list of administrative division properties to find the desired properties
(* next is do the work to crunch the data together…not done because of the next bullet *)
I can guess that bringing all AdministrativeDivisions into memory would fail on some machines.
Further, I found a lot of the properties have missing data when querying for counties. The data is much more prevalent when querying for states. Of course both are AdministrativeDivisions and thus have the same set of properties.
The code (in the Notebook) attached is just a sketch of how this method could be accomplished. A full application could be created from this sketch.
Thanks for posting this Alan. Two things come up now:
Where can I find these constants you use in your code?
“ContinentalUSStates”
“AllUSStatesPlusDC”
When I run this code on Windows V10.1 (no changes), I get a blank map after all these messages come out (see attached). Is this a simple fix?
GeoRegionValuePlot::noents: no valid location → value pairs found >>
Transpose::nmtx: The first two levels of {} cannot be transposed. >>
Set::shape: Lists {SystemGeoPlotsDumpgeostuff$159588,SystemGeoPlotsDumpvalues$159588} and Transpose[{}] are not the same shape. >>
Transpose::nmtx: The first two levels of {SystemGeoPlotsDumpgeostuff$159588,{}} cannot be transposed. >>
General::stop: Further output of Transpose::nmtx will be suppressed during this calculation. >>
$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of SystemGeoPlotsDumpgeostuff$159588->SystemGeoPlotsDumpgeostuff$159588. >>
$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of SystemGeoPlotsDumpgeostuff$159588->SystemGeoPlotsDumpgeostuff$159588. >>
I had suppressed output since that was in Alan’s sample code. Now, unsuppressed, it looks like Mma V10.0 (Home) Win8,1 also comes back unevaluated from that command.
Actually on my home network (where I now am) it seems to be trying to evaluate… going very slow (as these cloud data computations often go-often -making them difficult to use for computationally intensive work)
And the progress box under says things like “Downloading 157 of 3143 values…” so the 3143 is the number of counties. But it also throws error messages like"EntityValue::nodat: Unable to download data. Some or all results may be missing."
In my experience, things like this sometimes get in the way of seriously using the Entity framework for significant computations–slow downloads and deterministically unreliable download failures (sometimes none and sometimes random ones timing out–so the computation cannot be trusted to complete)
Still waiting after 5 minutes for the first retrieval of the 3143 to complete… stay tuned…
UPDATE: Well it is taking forever so I am aborting it…
Thanks, Alan. When I tried the code this morning it failed in the first cell with the error “EntityValue::ctimeout: A computation timed out.” I still get the error, however it worked for me just now. I find the syntax and constants a bit mysterious. Can you recommend some documentation that covers the usages in your reply?