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
bysort year : egen x=count() / bysort year : egen x=mean()Hello Statalist colleagues, I hope you are all staying healthy. I had a question while struggling …
Using egen to create new treatment variableHi, I am looking at a study involving student performance and gender. Students are observed taking …
Refer to multiple variables in StataHi, My variables' names are something like var11, var11_oth, var12, var12_oth, var13, var13_oth.etc…
Staggered diff in diffHey everyone, I will be evaluation a policy consisting on granting property rights to communities, …
Panel Data ProbabilitiesHello, I have panel data looking like the following: Code: * Example generated by -dataex-. For m…
Subscribe to:
Post Comments (Atom)
0 Response to Transforming dataset into a panel dataset
Post a Comment