Dear STATA-Users,
I am working on a data set which currently looks like that: (The data is sorted already using: sort id date_start)
id date_start date_end policy1 policy2 policy3 policy 4
1 1 Apr 2020 3 Apr 2020 1 0 0 0
1 1 Apr 2020 3 Apr 2020 0 2 0 0
1 1 Apr 2020 2 Apr 2020 0 0 1 0
1 2 Apr 2020 . 0 0 0 1
1 3 Apr 2020 . 0 0 0 0
1 3 Apr 2020 . 0 0 0 0
2 1 Apr 2020 2 Apr 2020 0 1 0 0
2 2 Apr 2020 3 Apr 2020 1 0 0 0
2 2 Apr 2020 6 Apr 2020 0 0 0 1
2 3 Apr 2020 1 May 2020 0 0 1 0
I started coding a qualitative data set where policies are described in written form, where each observation (i.e. line) described a policy. I generated new variables (i.e. policy1, policy2, etc. which are coded as dummies or variables taking ordinal values). he data includes a large number of different policies in different countries (id), the date when the policy was introduced (date_start) and the date the policies end (date_end). When there are missings in date_end this means the policy is introduced for only one day.
I would like to create a panel data set with id as the panel variable and date as the time variable and I would like to carry on the values of each policy when it is introduced until the date when the policy ends.
I already managed to replace the values when each policy was introduced for each duplicate starting date. So I get all observations of policy variables in the same line. My idea was to be able to drop duplicate observations in terms of date-start later. So my data now looks like that:
id date_start date_end policy1 policy2 policy3 policy 4
1 1 Apr 2020 3 Apr 2020 1 2 1 0
1 1 Apr 2020 3 Apr 2020 1 2 1 0
1 1 Apr 2020 2 Apr 2020 1 2 1 0
1 2 Apr 2020 . 0 0 0 1
1 3 Apr 2020 . 0 0 0 0
1 3 Apr 2020 1 Apr 2020 0 0 0 0
2 1 Apr 2020 2 Apr 2020 0 1 0 0
2 2 Apr 2020 3 Apr 2020 1 0 0 1
2 2 Apr 2020 6 Apr 2020 1 0 0 1
2 3 Apr 2020 1 May 2020 0 0 1 0
But from here I do not manage to carry on the values of each policy until date_start takes the value of date_end when the policy was introduced. So e.g. policy1 should take the value 1, when at date 1 Apr 2020 and should remain 1 until the date 3 Apr 2020.
I am happy for any help in this regard.
Many thanks and best,
Sophie
Related Posts with Transforming dataset into a panel dataset
Including an extra independent variable in a panel regression reports missing t-statistics/std. errorsHello everyone, I have a panel dataset, where the panel variable is industry code (I am doing an in…
Help with creating a dummy variable that depends on the last integer of a dateHey y'all. I've been stuck on creating a dummy variable called summer that's 1 when the integer end…
bar chart width of barsHi i created this bar chart using the bar chart option within the data tab in stata and i produced t…
Help with code for confidence bonds for QQplot of residualsHi guys, I am running a multiple linear regression model and to check the assumption of normality o…
Presenting industry and year coefficient using a 3D graphHi all I regress y on X1 and X2 per each industry and year group. My coefficient of interest is the…
Subscribe to:
Post Comments (Atom)
0 Response to Transforming dataset into a panel dataset
Post a Comment