Announcement

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

  • How to truncate string variables i.e. postcodes.

    Hi there, how does one truncate a string variable such as a postcode in Stata? The variable comprises characters and numbers in this format e.g. XXX, XX, and I would like to truncate the variable to the first two characters. There are 1,400 observations. Much appreciated.

  • #2
    Code:
    gen wanted= substr(postcode, 1, 2)
    See

    Code:
    help substr()

    Comment


    • #3
      Hi there, how do i save data in stata? thanks

      Comment


      • #4
        this question has nothing to do with this post and you should have started a new topic; but see
        Code:
        help save

        Comment


        • #5
          you type in Stata help save and you will see that the command to save data is called save. Now be careful: Never overwrite the original data.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment

          Working...
          X