![]() ![]() ![]() The distances stored in the new ‘km’ variable are air distances as opposed to road distances. The distance between each of these cities from New York will be stored in a new variable generated called ‘km’. The latitude and longitude of other cities are stored in ‘’latitudes’ and ‘longitudes’ respectively. We type the following command with the first two arguments being the latitude (40.697132) and longitude (-73.931351), respectively, of New York. Let’s say we wish to find the distance of New York from other cities in the US. Calculating the Distance of New York From Other Cities The double format is more precise and accurate than float. Whenever working with distances, or the geodist command, it is a good idea to store values in variables with the double format rather than the float format. Other optional options can also be added.īy default, this command generates distances in kilometers. The option of generate()is necessary, and allows us to specify the name of the variable that will be generated to store the distance between the two locations. The latitude must always be written before the longitude. The first two arguments are the latitude and longitude of the first location, followed by the latitude and longitude of the second location. The general syntax of the command is as follows: geodist lat1 lon1 lat2 lon2, generate(new_dist_var) Stata’s working directory can be changed through: cd “directory path” Syntax of geodist Make sure the working directory of your Stata file is the same as the working directory of the data file. To load the dataset, we type: use "distance.dta", clear ![]()
0 Comments
Leave a Reply. |