Announcement

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

  • add a day and row

    Hi all,

    I need add a day in the next row if some variable have some value.

    for example:

    +---------------------------------------------------+
    | bday bdaynew bday |
    |-----------------------------------------------------|
    1. | 01/03/60 03jan1960 12 |
    2. | 03/22/01 22mar2001 15066 |
    3. | 08/18/04 18aug2004 16311 |
    4. | 10/12/74 12oct1974 5408 |
    +----------------------------------------------------+

    if bday=12

    +--------------------------------------------+
    | bday bdaynew bday |
    |------------------------------------------------|
    1. | 01/03/60 03jan1960 12 |
    2. | 02/03/60 03jan1960 13
    3 03/22/01 22mar2001 15066 |
    4. | 08/18/04 18aug2004 16311 |
    5. | 10/12/74 12oct1974 5408 |
    +----------------------------------------------+

    Thanks in advance

    Regards
    Ro
    Last edited by Rodrigo Badilla; 28 Apr 2014, 23:13.

  • #2
    You have bday given twice above! I note also that as daily dates the last variable (column) is

    Code:
    13jan1960
    01apr2001
    28aug2004
    22oct1974
    Any way, consider

    Code:
    local Np1 = _N + 1
    expand 2 if bday == 12
    replace bday = bday + 1 in `Np1'/L
    We want two copies of those observations. expand adds extra observations at the end of the data. Hence we keep track of where they are by noting the number of observations _N before we expand.

    Please register with your full real name. See the Advice Guide in the FAQ and the Contact us button on the home page.

    Comment


    • #3
      Hi Nick,

      Thanks for you reply, your code work so fine for my data!

      How i should modify to add a new row before the date (add a row in the upper row if bday=12??)

      thanks for you information!
      Regards
      Ro

      Comment


      • #4
        I don't understand how this is a different question. expand copies observations exactly; if you want to modify values use replace; if you want to change the sort order use sort.

        Please register with your full real name. See the Advice Guide in the FAQ and the Contact us button on the home page.

        Comment

        Working...
        X