Announcement

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

  • how to add*observations at the end of the observations for existing variables?

    When name and year exist, I cannot use the command below because it says variables already exist. how to insert some observations quickly?
    Code:
    input expName year
    刘洋   2015
    彭蓉   2015
    方静   2016
    杜海燕   2015
    石书田   2015
    邵宗义   2015
    金源祎   2016
    陈伯爽   2015
    end
    ​​​​​​​I know a stupid way is
    set obs ...
    replace ...in...

    But when I have a lot of observations to add, I guess there should be a better and more direct way.
    Thanks!

  • #2
    Probably the fastest way is to -save- your original dataset, -insert- your new data, and then -append-. Illustrated below (begin at the "Begin here" comment).

    .ÿ
    .ÿversionÿ17.0

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿquietlyÿinputÿstr20ÿNameÿintÿyear

    .ÿ
    .ÿcount
    ÿÿ8

    .ÿ
    .ÿ*
    .ÿ*ÿÿBeginÿhere
    .ÿ*
    .ÿtempfileÿoriginal

    .ÿquietlyÿsaveÿ`original'

    .ÿ
    .ÿ//ÿAddÿnewÿdataÿ(aÿlotÿofÿobservations)
    .ÿdropÿ_all

    .ÿquietlyÿinputÿstr20ÿNameÿintÿyear

    .ÿ
    .ÿappendÿusingÿ`original'

    .ÿ
    .ÿcount
    ÿÿ16

    .ÿ
    .ÿ//ÿDone
    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      Probably the fastest way is to -save- your original dataset, -insert- your new data, and then -append-. Illustrated below (begin at the "Begin here" comment).

      .ÿ
      .ÿversionÿ17.0

      .ÿ
      .ÿclearÿ*

      .ÿ
      .ÿquietlyÿinputÿstr20ÿNameÿintÿyear

      .ÿ
      .ÿcount
      ÿÿ8

      .ÿ
      .ÿ*
      .ÿ*ÿÿBeginÿhere
      .ÿ*
      .ÿtempfileÿoriginal

      .ÿquietlyÿsaveÿ`original'

      .ÿ
      .ÿ//ÿAddÿnewÿdataÿ(aÿlotÿofÿobservations)
      .ÿdropÿ_all

      .ÿquietlyÿinputÿstr20ÿNameÿintÿyear

      .ÿ
      .ÿappendÿusingÿ`original'

      .ÿ
      .ÿcount
      ÿÿ16

      .ÿ
      .ÿ//ÿDone
      .ÿ
      .ÿexit

      endÿofÿdo-file


      .

      Great! Thanks for this tip!

      Comment

      Working...
      X