Announcement

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

  • How to add only one observation to a variable?

    Hi all,

    One question, I hope that if you can help me answer it.

    I want to add an observation at the end of a column. For example, I have a variable X with 10 observations and I want to add an observation so that instead of being 10 the variable has 11 observations. Is there any command that gives me this operation?

    Thanks

  • #2
    Well, you can. But note that you are not adding one observation to "variable X". You are adding one observation *to your entire dataset*, of which you are only adding information for the variable X. This is do-able, but I wouldn't suggest going that way. In any case, warning is given. You could try:

    Code:
    set obs `=_N+1'
    replace X = 1 if _n == _N

    Comment


    • #3
      Two other possibilities, for the record:

      Code:
      insobs 1
      Code:
      mata st_addobs(1)

      And for the replace:
      Code:
      replace X=1 in L

      The last L is allowed in lowercase or uppercase, I use uppercase here for readability. It can also be written with "minus one":
      Code:
      replace X=1 in -1
      Last edited by Jean-Claude Arbaut; 24 Jun 2019, 14:11.

      Comment

      Working...
      X