Hello,
I'm seeking assistance with what appears to be a seemingly simple task, but I'm currently struggling to manage it effectively.
I possess Firm and Executive IDs that are matched with Year and a variable of interest, CNS, which is associated with combinations of Exe_ID and Year. My objective is to create a new variable, CNS_Constant, which would assume the average values of CNS based on the first two years.
In the provided data example, you can observe only Firm, 4295899290, but my dataset includes numerous other firms.
Example:
The first Executive with the ID 18101 has observations for only one year, which is 2010. In this case, the CNS_Constant variable for this Executive should be marked as missing as the average should be calculated based on the first two years.
Executive 35166, on the other hand, has CNS data for the years 2012 to 2016. For this Executive, across all years, CNS_Constant should take on the value representing the average of the values assigned to the first two years, specifically 2012 and 2013. That is, the average should be calculated from the values: -1.126891, -1.11928, -1.113155, -1.107945, -1.805381, -1.802821, -1.800401, and -1.798125.
Any guidance or assistance on how to accomplish this task would be greatly appreciated.
I'm seeking assistance with what appears to be a seemingly simple task, but I'm currently struggling to manage it effectively.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double FirmID long Exe_ID int Year float CNS 4295899290 18101 2010 -.04134016 4295899290 18101 2010 -.04134016 4295899290 18101 2010 -.04134016 4295899290 35166 2012 -1.1268909 4295899290 35166 2012 -1.1192799 4295899290 35166 2012 -1.1131546 4295899290 35166 2012 -1.1079446 4295899290 35166 2013 -1.8053812 4295899290 35166 2013 -1.8028207 4295899290 35166 2013 -1.8004007 4295899290 35166 2013 -1.7981247 4295899290 35166 2014 .9342402 4295899290 35166 2014 .9355524 4295899290 35166 2014 .9365929 4295899290 35166 2014 .9376943 4295899290 35166 2015 .5666934 4295899290 35166 2015 .5674239 4295899290 35166 2015 .5679057 4295899290 35166 2015 .53309023 4295899290 35166 2016 .12444775 end
I possess Firm and Executive IDs that are matched with Year and a variable of interest, CNS, which is associated with combinations of Exe_ID and Year. My objective is to create a new variable, CNS_Constant, which would assume the average values of CNS based on the first two years.
In the provided data example, you can observe only Firm, 4295899290, but my dataset includes numerous other firms.
Example:
The first Executive with the ID 18101 has observations for only one year, which is 2010. In this case, the CNS_Constant variable for this Executive should be marked as missing as the average should be calculated based on the first two years.
Executive 35166, on the other hand, has CNS data for the years 2012 to 2016. For this Executive, across all years, CNS_Constant should take on the value representing the average of the values assigned to the first two years, specifically 2012 and 2013. That is, the average should be calculated from the values: -1.126891, -1.11928, -1.113155, -1.107945, -1.805381, -1.802821, -1.800401, and -1.798125.
Any guidance or assistance on how to accomplish this task would be greatly appreciated.
Comment