Announcement

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

  • Change all the values to zero for a certain period of time


    Hello!
    I'd like to get some advice.
    I have the following forms of data.

    I'd like to change all the "thrifty" values to zero for a certain period of time.
    In the data below, for example, I would like to change all the values of thrift from 01apr2015 to 02apr2015.
    If it goes as I intended, then "thrifty_nb" should be created.
    (The thrift value is only 0 or 1)

    Thanks!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id date thrifty thrifty_nb)
    1 20148 0 0
    1 20149 0 0
    1 20150 1 1
    1 20179 1 0
    1 20180 0 0
    2 20149 0 0
    2 20150 0 0
    2 20151 1 1
    2 20179 1 0
    2 20180 1 0
    2 20181 1 1
    end
    format %td date

  • #2
    The following should do what you want. The td() function is documented in the output of help datetime in the section "Conveniently typing SIF values".
    Code:
    . generate wanted = thrifty
    
    . replace wanted = 0 if inrange(date,td(01apr2015),td(02apr2015))
    (3 real changes made)
    
    . list, noobs sepby(id) abbreviate(12)
    
      +------------------------------------------------+
      | id        date   thrifty   thrifty_nb   wanted |
      |------------------------------------------------|
      |  1   01mar2015         0            0        0 |
      |  1   02mar2015         0            0        0 |
      |  1   03mar2015         1            1        1 |
      |  1   01apr2015         1            0        0 |
      |  1   02apr2015         0            0        0 |
      |------------------------------------------------|
      |  2   02mar2015         0            0        0 |
      |  2   03mar2015         0            0        0 |
      |  2   04mar2015         1            1        1 |
      |  2   01apr2015         1            0        0 |
      |  2   02apr2015         1            0        0 |
      |  2   03apr2015         1            1        1 |
      +------------------------------------------------+

    Comment


    • #3
      Dear. William Lisowski

      Thank you very much!
      Thanks to you, I'm learning today, too!

      Comment

      Working...
      X