Hi everyone,
I need some feedback, and potentially some code corrections please.
Basically, I want to create a new variable called -tariff_3_more_50000_w-. It should be equal to 1 if values are greater than 50,000, and 0 otherwise.
But, this new variable depends on a lot of conditions:
The last line corresponds to the sample that I want to keep, i.e. contracted powers per period (variables -power_p`i') below 50,000.
Could you give me plese some suggestions for improving the code to make it what I want it to be, or if some styling improvements would be possible?
Thanks in advance.
Best,
Michael
I need some feedback, and potentially some code corrections please.
Basically, I want to create a new variable called -tariff_3_more_50000_w-. It should be equal to 1 if values are greater than 50,000, and 0 otherwise.
But, this new variable depends on a lot of conditions:
- If one of the values of power_p1 power_p2 power_p3 power_p4 power_p5 power_p6, or all the values of these variables for each of the observations is greater than 50,000.
- this new variable -tariff_3_more_50000_w- also depends on another variable: -tariff_3-. -tariff_3- is a dummy variable equal to 1 if the contract in question has tariff values 3.0 3.0A and 3.1a , 0 other.
- Under no circumstances should this new variable be equal to 1 if all or some of the values for each observation for the variables power_p1 to power_p6 are missing.
- Finally, let's imagine that power_p1 equals 100, and power_p6 equals 125,000. The new variable tariff_3_more_50000_w should be equal to 1, even if only one of the values is greater than 50,000.
Code:
gen tariff_3 = 1 if inrange(tariff_ekon_id_encod, 11,13) // tariffs 3.0, 3.0 and 3.1a replace tariff_3 = 0 if tariff_3 == . gen tariff_3_more_50000_w = tariff_3 == 1 & ((power_p1 >50e3 & !missing(power_p1)) /// | (power_p2 >50e3 & !missing(power_p2)) /// | (power_p3 >50e3 & !missing(power_p3)) /// | (power_p4 >50e3 & !missing(power_p4)) /// | (power_p5 >50e3 & !missing(power_p5)) /// | (power_p6 >50e3 & !missing(power_p6))) replace tariff_3_more_50000_w = . if tariff_3 == 1 & (missing(power_p1) /// & missing(power_p2) /// & missing(power_p3) /// & missing(power_p4) /// & missing(power_p5) /// & missing(power_p6)) drop if tariff_3 == 1 & tariff_3_more_50000_w == 1
Could you give me plese some suggestions for improving the code to make it what I want it to be, or if some styling improvements would be possible?
Thanks in advance.
Best,
Michael
Comment