Announcement

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

  • Filling in missing observations based on sequence number

    Hello,

    I am trying to fill in the "town" variable in my dataset, and I cannot think of any Stata code to do it (please refer to the picture I have attached for this question). For all the missings of "town" that come after "ABINGTON" and before "ACTON", I'd like it to say "ABINGTON"; for those after "ACTON" and before the next value, I'd like those to say "ACTON", and so on. Is there a way to do that using the seqnum variable? I hope my question is not too confusing and that the screenshot is helpful. Thanks so much for your advice.

    Khat
    Attached Files
    Last edited by Khat Naing; 29 Dec 2017, 01:01.

  • #2
    This is an FAQ

    https://www.stata.com/support/faqs/d...issing-values/

    Code:
    replace town = town[_n-1] if missing(town)
    Almost certainly you should want to drop these observations

    Code:
    drop if A == TOWN
    I'll stop there but you need more work on this dataset. Do please read and act on https://www.statalist.org/forums/help#stata and don't post attachments; post example data.

    Comment


    • #3
      Welcome to the Stata Forum / Statalist,

      Please take some time to read the FAQ. There you'll find instructions about the best way to share command/data/output. Indeed, snapshots are not a good resource, for several reasons. Among them, those who are prompt to help you will have the burden to type a toy example before informing you the command.

      That said, I believe this will be a safe strategy to your case:

      Code:
      replace town = town[_n-1] if town==""
      Edit: crossed with Nick's reply.
      Best regards,

      Marcos

      Comment


      • #4
        Thank you so much for the advice, and I apologize for my mistakes. It's my first year using Stata, and I am still learning. Appreciate all pointers.

        Best,

        Khat

        Comment

        Working...
        X