Announcement

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

  • Potential help/manual error for spdistance stored results

    I am using spdistance in Stata 18.5 for Windows and noticed a potential error in the help/manual. Hoping others can either confirm it or point out something I'm missing before I contact Stata.

    In short, this is my first time using spdistance and I noticed that help and manual both refer to distance between being stored in r(dist). When I tried to use r(dist) to preserve results, I got an error and I realized the local was empty. When I tried again using r(distance), the code worked as expected (i.e. the value returned by spdistance is preserved in a distance variable). Sample code below to replicate what I'm seeing--am I correct that spdistance stores distance between in r(distance), not r(dist) as indicated in help/manual, and that help/manual should be corrected? Thanks.

    Code:
    capture clear
    
    input byte id byte x byte y float lon float lat
        1 0 0  -96.2458 30.5533
        2 3 4  -73.9823 40.7533
        3 5 12 -19.6068 63.6329
        4 8 15  28.8686 41.0006
    end
    
    gen xy_dist = .
    gen xy_distance = .
    
    gen lonlat_dist = .
    gen lonlat_distance = .
    
    spset id, coord(x y)
    
    forval z = 2/4 {
        spdistance 1 `z'
        
        di "Stored in r(dist): `r(dist)'"
        capture replace xy_dist = `r(dist)' if id == `z'
        
        di "Stored in r(distance): `r(distance)'" _n(2)
        capture replace xy_distance = `r(distance)' if id == `z'
    }
    
    spset, modify coord(lon lat) coordsys(latlong, miles)
    
    forval z = 2/4 {
        spdistance 1 `z'
        
        di "Stored in r(dist): `r(dist)'"
        capture replace lonlat_dist = `r(dist)' if id == `z'
        
        di "Stored in r(distance): `r(distance)'" _n(2)
        capture replace lonlat_distance = `r(distance)' if id == `z'
    }

  • #2
    I'd report it.

    Comment

    Working...
    X