Announcement

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

  • Error when trying to generate new variable

    Hi

    I experienced an error when trying to generate a new variable for distance using geodist.

    Here is the command 'geodist -73.147705 -36.824261 -73.146629 -36.838622, gen(d)'

    Here is the error message that I see 'lat/lon are not variables, nothing to generate'.

    Does anyone know how I can address this?

    I am also wondering how we should use the variable in the dta files. For instance, if column D is longitude1, column E is latitude1, and column H is longitude2, column I is latitude2, is there any way we can loop the geodist? e.g. geodist D E H I, gen(d)', which does not work.

    I also tried 'gen d= geodist -73.147705 -36.824261 -73.146629 -36.838622' but got the error message 'geodist not found'


    Thank you!
    Last edited by Guo Pei; 09 Jan 2017, 01:16.

  • #2
    In Stata variables are the columns in a data set. What you have done is given geodist numers rather than variables. Variables are required when you use the generate() option, so now the error message makes sense: it expected the latitude and longitude in variables and you did not give it in that form.

    geodist D E H I, gen(d) should work assuming D E H I are appropriate variables, which we cannot know as you did not give us an extract from the data (see help dataex).

    geodist with the generate() option will do the looping automatically. In Stata we very very very rarely loop over observations. It is so rare that it is pretty much a guarantee that you are doing something wrong when you loop over observations.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks so much for the reply! I tried the command 'geodist Caleta_longitude Caleta_latitude Feria_longitude Feria_latitude, ' and got 'Was expecting a variable, scalar, or number instead of Caleta_longitude'. I have attached both screenshots of the dta file as well as STATA command. Will you happen to have any insights? Thank you!
      Attached Files

      Comment


      • #4
        Please do read advice in the FAQ on not posting screenshots. http://www.statalist.org/forums/help#stata 12.5

        Your latitude and longitude variables are string variables given the header line in observation 1. Stata is not a spreadsheet application in which you can sprinkle data cells with metadata as if you were in Excel.

        Try

        Code:
        drop in 1/2 
        destring *ude, replace

        Comment


        • #5
          Hi I apologize for this. Thanks so much for the kind assistance!

          Comment

          Working...
          X