Hello Statalist,
I need some help, it is probably something simple and basic but I cannot see a way to do it quickly without devoting a lot of time to manually picking and doing this...
1) I'm working with a panel dataset that looks similar to the following example:
I need to generate a quarterly subsample by year and state. As you can see all counties have the same value of variable "inf" for the same year and quarter, then I need to keep only 1 observation by year, quarter, and state. My final subsample would look like the following:
2) I have an annual panel dataset per state (let's call it Dataset "Velocity"):
My working dataset is quarterly and by state and county (like the first example in question (1) of this post). I need to create the variable "vel" in my working dataset. The value of "vel" in the working dataset would be the same for all counties and quarters as the "vel" value in the dataset "Velocity" for that respective State and year. The additional problem here is that there are some counties, in this example county "C" (State XI), that the value of "vel" should be the average of the value of "vel" of some states in that respective year, for that reason, in this example, the value of "vel" 1991 (all quarters) of State "XI" is the average of the value of "vel" in 1991 for states "NE" and "AK". There are more of this case, for example, it could be a state "XA" as an average of states "AL and NE", etc... the final dataset that I need would look like this:
Thank you very much in advance for your help.
I need some help, it is probably something simple and basic but I cannot see a way to do it quickly without devoting a lot of time to manually picking and doing this...
1) I'm working with a panel dataset that looks similar to the following example:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte quarter str2 state str1 county float inf 1991 1 "AL" "A" .3 1991 1 "AL" "B" .3 1991 1 "AK" "A" .17 1991 1 "AK" "B" .17 1991 2 "AL" "A" .8 1991 2 "AL" "B" .8 1991 2 "AK" "A" .2 1991 2 "AK" "B" .2 end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte quarter str2 state float inf 1991 1 "AL" .3 1991 1 "AK" .17 1991 2 "AL" .8 1991 2 "AK" .2 end
2) I have an annual panel dataset per state (let's call it Dataset "Velocity"):
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year str2 state float vel 1991 "AL" 1 1991 "AK" 1.2 1991 "NE" 1.8 1992 "AL" 1.4 1992 "AK" 1.1 1992 "NE" 1.5 end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte quarter str2 state str1 county byte othervariables float vel 1991 1 "AL" "A" . 1 1991 1 "AL" "B" . 1 1991 1 "AK" "A" . 1.2 1991 1 "AK" "B" . 1.2 1991 1 "NE" "A" . 1.8 1991 1 "NE" "B" . 1.8 1991 1 "XI" "C" . 1.3 1991 2 "AL" "A" . 1 1991 2 "AL" "B" . 1 1991 2 "AK" "A" . 1.2 1991 2 "AK" "B" . 1.2 1991 2 "NE" "A" . 1.8 1991 2 "NE" "B" . 1.8 1991 2 "XI" "C" . 1.3 1991 3 "AL" "A" . 1 1991 3 "AL" "B" . 1 1991 3 "AK" "A" . 1.2 1991 3 "AK" "B" . 1.2 1991 3 "NE" "A" . 1.8 1991 3 "NE" "B" . 1.8 1991 3 "XI" "C" . 1.3 1991 4 "AL" "A" . 1 1991 4 "AL" "B" . 1 1991 4 "AK" "A" . 1.2 1991 4 "AK" "B" . 1.2 1991 4 "NE" "A" . 1.8 1991 4 "NE" "B" . 1.8 1991 4 "XI" "C" . 1.3 1992 1 "AL" "A" . 1.4 1992 1 "AL" "B" . 1.4 1992 1 "AK" "A" . 1.1 1992 1 "AK" "B" . 1.1 1992 1 "NE" "A" . 1.5 1992 1 "NE" "B" . 1.5 1992 1 "XI" "C" . 1.3 1992 2 "AL" "A" . 1.4 1992 2 "AL" "B" . 1.4 1992 2 "AK" "A" . 1.1 1992 2 "AK" "B" . 1.1 1992 2 "NE" "A" . 1.5 1992 2 "NE" "B" . 1.5 1992 2 "XI" "C" . 1.3 1992 3 "AL" "A" . 1.4 1992 3 "AL" "B" . 1.4 1992 3 "AK" "A" . 1.1 1992 3 "AK" "B" . 1.1 1992 3 "NE" "A" . 1.5 1992 3 "NE" "B" . 1.5 1992 3 "XI" "C" . 1.3 1992 4 "AL" "A" . 1.4 1992 4 "AL" "B" . 1.4 1992 4 "AK" "A" . 1.1 1992 4 "AK" "B" . 1.1 1992 4 "NE" "A" . 1.5 1992 4 "NE" "B" . 1.5 1992 4 "XI" "C" . 1.3 end
Comment