Announcement

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

  • How to repeat a variable value in a column?

    Hello, I have a small dataset below,
    clear
    input str80 name str90 symbol
    "F-000509" "Environmental Projects4502 - Parks Consolidated Construction Fund"
    " " "Future Bond Election "
    "F-000703" "Swimming Pool Upgrades"
    " ""4502 - Parks Consolidated Construction Fund"
    " ""Future Bond Election"
    "F-000708" "Parking garage Upgrades"
    end

    I want to repeat the value of the first column "name" to fill the gap between the name values.
    This is just for illustration.
    In fact, the real dataset has many name values and the gap between name values is unequal.
    Thanks for your help with the Stata code.
    Last edited by smith Jason; 17 May 2022, 06:22.

  • #2
    This is an FAQ

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

    Comment


    • #3
      Thank you!
      I try the two commands below, however, they don't work.
      replace name = name[_n-1] if name == ""
      replace name = name[_n+1] if missing(name)

      Comment


      • #4
        It looks as if you have spaces there,not empty strings.


        Code:
        replace name = name[_n-1] if trim(name) == ""

        Comment


        • #5
          Thank you!

          Comment

          Working...
          X