Announcement

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

  • spmap point data: Display Alaska and Hawaii next to contiguous United States

    Dear Users, I want to draw a point map with locations of firms by coordinates displaying Alaska and Hawaii next to contiguous United States following a previous discussions by Scott Merryman and others here. The location points of the two firms in Alaska do not move with Alaska. How can I make the two locations in the North West corner move with Alaska?

    Code:
    clear
    
    input _X _Y
    
    -86.82805 33.527872 
    -86.260844 32.331872 
    -149.7621 61.1919 
    -147.56838 64.81859 
    -112.08791 33.494514 
    -114.08271 35.285985 
    -92.294471 34.766541 
    
    end
    
    save location, replace
    
    copy https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_500k.zip  cb_2015_us_state_500k.zip, replace
    unzipfile cb_2015_us_state_500k.zip, replace
    shp2dta using  cb_2015_us_state_500k, data("us_data")  coor("us_coordinates") genid(id) gencentroids(c) replace
    
    use us_data, clear
    quietly destring STATEFP, generate(fips)
    drop if fips > 56
    
    save usstates,replace
    
    l fips id  if fips == 2 | fips == 15
    
    use us_coordinates,clear
    
    gen order = _n
    
    drop if _X < -165 & _X != . &  _ID == 50
    replace _X = _X  + 55  if  _X != .  &  _ID == 50
    replace _Y = _Y  + 4  if _Y != .  &  _ID == 50
    replace _X = _X*.4  -55 if  _X !=  . &  _ID == 15
    replace _Y = _Y*.4  + 1 if _Y != .  & _ID == 15
    drop if _X > -10 & _X != . & _ID == 15
    sort order 
    sort _ID
    drop order
    save us_coordinates2,replace
    
    use usstates,clear
    
    spmap using us_coordinates2  , id(id) point(data("location.dta") x(_X) y(_Y) shape(triangle) size(*1.0) fcolor(lime) ocolor(white) osize(vvthin))

  • #2
    Hi Lynn,

    Sorry to hear you are still working on this, but glad to know you've made some progress. Seems like you need to take your Alaska coordinates and transform them exactly the same way you've transformed the polygon for Alaska. i.e.

    Code:
    * Alaska
    drop if _X &gt; 0 &amp; !mi(_X) &amp; _ID == 37  // land in the Eastern hemisphere
    geo2xy _Y _X if _ID == 37, replace proj(albers)
    replace _Y = _Y / 3 + 700000 if _ID == 37
    replace _X = _X / 3 - 1700000 if _ID == 37
    It looks like you read the point data in, save it to the "location" dataset, then you load "us_coordinates" and transform that, but I don't see you ever go back and transform the "location" dataset. At the top of the script, before save location, replace, you should include a dummy variable that identifies whether or not a firm is located in Alaska. then something like this should work:

    Code:
    geo2xy _Y _X if in_alaska, replace proj(albers)
    replace _Y = _Y / 3 + 700000 if in_alaska
    replace _X = _X / 3 - 1700000 if in_alaska

    Comment


    • #3
      Hi Daniel,
      Thank you very much for getting back to me.
      I tried the code but it did not work either option.
      Can you do me a favor checking this by positioning your code in my mine please?
      The Alaska coordinates in the data are

      -149.7621 61.1919 -147.56838 64.81859 Thank you so much once again for your patience and help. Lynn

      Comment


      • #4
        Oh, looks like I misunderstood something: I thought you were using Robert Picard's improvement on Scott Marryman's code, but you're not using geo2xy at all. Okay. Regardless, the strategy is still the same. You will need to translate your Alaska point data the same way you translated your Alaska polygon. This appears to work on my end.

        Code:
        clear
        
        input _X _Y in_alaska
        
        -86.82805 33.527872 0
        -86.260844 32.331872 0
        -149.7621 61.1919 1
        -147.56838 64.81859 1
        -112.08791 33.494514 0
        -114.08271 35.285985 0
        -92.294471 34.766541 0
        
        end
        
        replace _X = _X*.4  -55 if  _X !=  . &  in_alaska
        replace _Y = _Y*.4  + 1 if _Y != .  & in_alaska
        
        save location, replace
        
        copy https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_500k.zip cb_2015_us_state_500k.zip, replace
        unzipfile cb_2015_us_state_500k.zip, replace
        shp2dta using cb_2015_us_state_500k, data("us_data") coor("us_coordinates") genid(id) gencentroids(c) replace
        
        use us_data, clear
        quietly destring STATEFP, generate(fips)
        drop if fips > 56
        
        save usstates,replace
        
        l fips id  if fips == 2 | fips == 15
        
        use us_coordinates,clear
        
        gen order = _n
        
        drop if _X < -165 & _X != . &  _ID == 50
        replace _X = _X  + 55  if  _X != .  &  _ID == 50
        replace _Y = _Y  + 4  if _Y != .  &  _ID == 50
        replace _X = _X*.4  -55 if  _X !=  . &  _ID == 15
        replace _Y = _Y*.4  + 1 if _Y != .  & _ID == 15
        drop if _X > -10 & _X != . & _ID == 15
        sort order 
        sort _ID
        drop order
        save us_coordinates2,replace
        
        use usstates,clear
        
        spmap using us_coordinates2  , id(id) point(data("location.dta") x(_X) y(_Y) shape(triangle) size(*1.0) fcolor(lime) ocolor(white) osize(vvthin))

        Comment


        • #5
          Hi Daniel, it works perfectly now. Thank you so much once again for your valuable time and patience. Lynn.

          Comment

          Working...
          X