Announcement

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

  • Adding new lines in a given data set

    For some reasons, I need to add a new line above a given data set to show the summations of variables, not to creat a new variable using gen command. The original data contains n observations, so after this manipulation, the numbers of observations become n+1. I know, for the simplest method, using append commend can achieve this work. However, it seems awkward to make it using two data sets. Is there any better method? Thanks!

  • #2
    Code:
    count
    set obs `=`r(N)'+1'
    will add an extra observation, with all values missing, to the data set.

    But I caution you that doing this is a very, very bad idea. Stata data sets are not spreadsheets. If you contaminate the Stata data with an observation containing summations of the variables, that extra observation will cause you endless trouble with almost everything you do with the data set from that point forward. You will have to remember to add an -if- or -in- clause to every command to exclude that observation from any calculations. And it is just a matter of when, not if, you will at some point forget to do that.

    If you are just trying to create a display of the data with totals in a row at the bottom, you would be better off exporting your data to a spreadsheet and then adding the row of summations there.

    Comment


    • #3
      Thanks very much for your reply, Your advise is very helpful and illuminating!

      Comment

      Working...
      X