Dear Stata Users,
I have a data example as shown below and I have a question about generating one of my main variables.
There are two IDs: 10 and 20, unit_a2 is just the first two numbers of unit_a4. unit_b comes from external data that I merged with my initial dataset.
Thank you very much,
JadLi
------------------ copy up to and including the previous line ------------------
I have a data example as shown below and I have a question about generating one of my main variables.
There are two IDs: 10 and 20, unit_a2 is just the first two numbers of unit_a4. unit_b comes from external data that I merged with my initial dataset.
- I need to generate the variable "department_prod". This is what the department in a company produces.
- The variable unit_a2 for ID=10 has values 36 and 40.
- So the "department_prod" must be equal to 1, otherwise, it must be equal to zero.
- If unit_a4=unita2, then the dummy is equal to 2 only if the ID (in this case 10) has more than one unit (3635 and 3640) that is within the same 4-digit unit number which starts by 36.
- In the case of ID=20, the "department_prod"=0 when unit_a4=unita2 because unit_4a =3620 and 2811 so they do not have the same 2-digit 36!= 28.
Thank you very much,
JadLi
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte id int(year unit_a4) byte(unit_a2 unit_b department_prod) 10 2004 3635 36 36 2 10 2004 3635 36 37 0 10 2004 3635 36 38 0 10 2004 3635 36 39 0 10 2004 3635 36 40 1 10 2004 3640 36 36 2 10 2004 3640 36 37 0 10 2004 3640 36 38 0 10 2004 3640 36 39 0 10 2004 3640 36 40 1 10 2004 3640 36 41 0 10 2004 4019 40 36 1 10 2004 4019 40 37 0 10 2004 4019 40 38 0 10 2004 4019 40 39 0 10 2004 4019 40 40 2 10 2004 4019 40 41 0 20 2004 3620 36 36 0 20 2004 3620 36 37 0 20 2004 3620 36 38 0 20 2004 3620 36 39 0 20 2004 3620 36 40 1 20 2004 3620 36 41 0 20 2004 3620 36 42 0 20 2004 2811 28 36 1 20 2004 2811 28 37 0 20 2004 2811 28 38 0 20 2004 2811 28 39 0 20 2004 2811 28 40 1 20 2004 2811 28 41 0 20 2004 2811 28 42 0 end

Comment