Announcement

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

  • Storing data all on one line

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(intervention vehicleno episodeno oil var6)
      1 1 1 0 .
    110 1 2 0 1
      1 2 1 1 .
      1 2 2 1 .
    112 2 3 1 1
      1 3 1 1 .
    113 3 2 1 1
    114 4 1 0 1
      1 4 2 0 .
      1 4 3 1 .
    115 4 4 1 1
    end

    Hi I would like to store data all on one line

    Each time the car came to the car depot - registered as episodeno, if it had anything done to it - registered as intervention.
    If it had an oil problem at any one time the vehicle went to the car depot registered as a 1.

    I would now just like to clean my dataset and just keep all data stored on one line as I will be merging with another dataset using the 'intervention' as the variable used to merge

    How do I create a column which if the vehicle had an oil failure at any episode it visited the car depot and for this to be stored on the line as the intervention?
    Therefore appearing as 'var6'

  • #2
    I have tried ,

    bys vehicleno (intervention) : gen max = Oil[_N] if intervention !=0

    but what this does is it looks at the max within each group of vehicle no but for eg for

    Vehicle 4 who had intervention 114 and 115

    if for intervention 115 the vehicle did not sustain an oil failure this should remain as 0 but with this code as 114 had an oil failure the code will code them all as 1 for vehicle 4

    Comment

    Working...
    X