Announcement

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

  • #16
    Danielle Teran: This does sound like a request for help with homework, which is against Statalist policy.

    I'll simply suggest that you're on the right track with the section of the maptile help file that you copied and pasted into your post. I'd encourage you to run -help maptile- in Stata and carefully click through Example 4. You might then want to read the detailed explanations of the mapif() option in the help file.

    Comment


    • #17
      Michael Stepner What? this is not a homework assignment. I am an intern with the county health department. A fellow intern was able to make the map, but she used a huge line of code to crop out all the zip codes that did not correspond to our data set. I wanted to know if there was a shorthand way to just exclude the zips with no data. I have already tried clicking through Example 4 and tried using mapif(). That is why I am reaching out.

      Comment


      • #18
        Michael Stepner

        Do you see this giant long code? I had to take a list of all zips in Harris county and paste into a word doc and then add in the code for all of them. As you can see, I'm still not even finished! Sure it works (I tried it using just a few zips and got what I wanted), but I just wanted something easier because it will take me a while to include all of Harris County zip codes into the code. As you can see, some zip codes are "missing" such as 77012, so I can't just tell stata to include 77002 to 77598 because I got an error when I tried to do that. I just wanted to know if there was an easier way, like if simpler code to exclude all missing data from the map, rather than trying to list out all the zips I want to include.
        Click image for larger version

Name:	zip code.PNG
Views:	1
Size:	38.3 KB
ID:	1401890

        Last edited by Danielle Teran; 13 Jul 2017, 14:13.

        Comment


        • #19
          Click image for larger version

Name:	Stray Map.png
Views:	1
Size:	33.1 KB
ID:	1401894 I can get the map I want using the long code I mentioned, I was just hoping there was a shorter version.

          Comment


          • #20
            Danielle Teran We can advise on some techniques to make this code shorter, but you must post your full syntax and tell us on what basis are you selecting the zip codes. Is it all the zip code within a range? is it zip codes that have identifier? Please follow the FAQ for better posting questions.

            Comment


            • #21
              Hi Danielle Teran, I definitely didn't understand that this was the issue you were grappling with from your initial post! As Oded mentioned, there is some excellent advice in the FAQ about how to pose questions in a way that helps others help you find a solution!

              There is almost certainly a simpler way to select the ZIPs in Harris County, but to find the most efficient solution we'd need to know what format the list of ZIPs in Harris County was in before you copied and pasted it into Word. Suppose you had a dataset "harris_county_zips.dta" with a variable named zip5. Then you could do something like:

              Code:
              merge 1:1 zip5 using harris_county_zips.dta, assert(1 3)
              gen harris_dummy = (_merge==3)
              drop _merge
              maptile count, geo(zip5) mapif(harris_dummy==1)

              Comment


              • #22
                Michael Stepner Thanks!

                Comment


                • #23
                  Michael Stepner How do I stop the bin numbers from overlapping? You notice how the bin says 55.0 - 117.0 and 117 - 401.0 I want it to be 55.0 -117.0 and 118 - 401.0
                  Otherwise, if someone was looking at the map, they may wonder if a zip code had 117 cases, would it fall into the orange or the burnt orange/red bin? I tried using the cutvalues command, but it still has overlapping bin numbers. Am I using the code wrong? I would like it to be something like: [ ] no data, [ ] 1-49, [ ] 50-99, [ ] 100-199, [ ] 200-299, [ ] 300-401
                  Thanks!

                  Click image for larger version

Name:	Example Graph.png
Views:	1
Size:	32.7 KB
ID:	1403195

                  Comment


                  • #24
                    Hi Danielle Teran, the edges of the bin are identical because maptile was designed with continuous data in mind. For example, if you specify a cutvalue of 50, then 49.99 will be included in the lower bin and 50.01 will be included in the upper bin—both of which round to 50. But I can understand why you want the legend labels to be distinct.

                    To label the legend in any custom way you'd like, you can use code like the following
                    Code:
                    twopt(legend(lab(2 "no data") lab(3 "1-49") ...))
                    See Example 3 in the maptile help file for a clickable example.

                    Comment


                    • #25
                      Michael Stepner Thank you! It worked perfectly! Although I left out the quotation marks because it wasn't needed and it looked a lot better in the legend without them. I finally have a map I can be proud of! Also, thanks for the explanation about the bins. That cleared things up for me. I appreciate it!

                      Comment


                      • #26
                        Danielle's question reminded me of something I wish I could achieve with maptile - plotting discrete values. for example I may have US counties and I wish to color each country according to some factor variable which has ~10 distinct values (for example 1-10). Every color/value should be distinct (as in 1 is blue, 2 is yellow, 3 is green, etc.) and not a scale. I was unable to achieve this with maptile - any suggestions?

                        Comment


                        • #27
                          Hi Ariel, here's an example that plots discrete values with distinct colors. I think it accomplishes what you're looking for?

                          Code:
                          sysuse census
                          rename (state state2) (statename state)
                          gen rand=ceil(runiform()*4)
                          maptile rand, geo(state) fcolor(blue red yellow green) twopt(legend(lab( 2 "1") lab(3 "2") lab(4 "3") lab(5 "4"))) cutv(1/3)

                          Comment


                          • #28
                            Brilliant, thanks!

                            Comment


                            • #29
                              Another query: is there an option to have the borders of counties (when plotting county data using for example the county2014 geography) thinner or even transparent?

                              Comment


                              • #30
                                Looking at the county2014_maptile.ado file, the outline thickness is hardcoded as vvthin:

                                Code:
                                os(vvthin ...) nds(vvthin) ///
                                You could change that. By default the county2014_maptile.ado file will be installed at "`c(sysdir_personal)'/maptile_geographies/county2014_maptile.ado", although the geofolder is configurable. You could edit the ado-file and hardcode a different value, or add a "geography-specific option" to specify it as an argument when you run maptile.

                                Comment

                                Working...
                                X