Announcement

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

  • Create a variable that is equal to 1 if "the below value" bigger than "the above value"

    Hello.
    I'd like to ask for help.
    I want to make goal, goal_pre, goal_post using by id and target.

    To create a goal
    in target, if "the below value" bigger than "the above value", it has 1.

    To create a goal_pre
    The value of goal goes up one by one.

    To create a goal_post
    The value of goal goes down one by one.

    What should I do?
    Thank!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 id float(target goal_pre goal goal_post)
    "A00011" 0 1 . .
    "A00011" 1 . 1 .
    "A00011" 1 1 . 1
    "A00011" 2 . 1 .
    "A00011" 2 1 . 1
    "A00011" 3 . 1 .
    "A00011" 3 . . 1
    "A00011" 2 . . .
    "A00011" 2 1 . .
    "A00011" 3 . 1 .
    "A00560" 1 . . .
    "A00560" 1 1 . .
    "A00560" 2 . 1 .
    "A00560" 2 1 . 1
    "A00560" 3 . 1 .
    "A00560" 2 . . 1
    "A00560" 1 1 . .
    "A00560" 3 1 1 .
    "A00560" 4 . 1 1
    end

  • #2
    No time variable?

    Comment


    • #3
      Dear Nick Cox
      I have "weekly" time variable
      for example, "01dec2019" means "First week of December 2019"
      but, STATA recognize as "daily" and time variable is not continuous.
      So I thought it was hard to use a time variable.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str6 id float(week target goal_pre goal goal_post)
      "A00011" 18232 0 1 . .
      "A00011" 18233 1 . 1 .
      "A00011" 18234 1 1 . 1
      "A00011" 18235 2 . 1 .
      "A00011" 18236 2 1 . 1
      "A00011" 18263 3 . 1 .
      "A00011" 18264 3 . . 1
      "A00011" 18297 2 . . .
      "A00011" 18322 2 1 . .
      "A00011" 18323 3 . 1 .
      "A00560" 18265 1 . . .
      "A00560" 18266 1 1 . .
      "A00560" 18294 2 . 1 .
      "A00560" 18295 2 1 . 1
      "A00560" 18296 3 . 1 .
      "A00560" 18297 2 . . 1
      "A00560" 18322 1 1 . .
      "A00560" 18323 3 1 1 .
      "A00560" 18324 4 . 1 1
      end
      format %td week

      Comment

      Working...
      X