I am trying to work my way into stata and I read a lot about how to build differences, but I can't seem to find a solution to my maybe a bit specific problem.
I have an large dataset (N>5000) with the following relevant variables:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(Sec Unit Value) 12 2215 2 13 2215 4 14 2216 4 15 2216 4 16 2216 4 17 2217 3 18 2217 3 19 2218 3 20 2218 3 21 2218 5 22 2218 5 23 2218 5 24 2219 5 25 2219 4 end label values Unit v2_Num label def v2_Num 2215 "05-002", modify label def v2_Num 2216 "05-003", modify label def v2_Num 2217 "05-004", modify label def v2_Num 2218 "05-005", modify label def v2_Num 2219 "05-006", modify
'Unit' marks a unit of analysis, each unit has a number, for ex. 05-004 which is repeated in every sec belonging to the unit.
I need to create another variable containing the difference between the 'Value' of the last and the 'Value' of the first second of every unit.
But as you can see, the units differ in lenght, some are just 2 sec, some much longer.
Is there any way I can do this? I have 5 datasets like this one and it is impossible to manage manually.
Help is much appreciated, thank you in advance!
Nad
0 Response to Seconds base date & Differing units of analysis: Generate variable containing differences between first and last second of a unit
Post a Comment