Hi all,

I have a dataset which looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float P str10 order_date str2(id a)
1 "2019-10-11" "1" "20"
1 "2019-10-11" "2" "30"
1 "2019-10-11" "3" "34"
1 "2019-10-11" "4" "12"
1 "2019-10-11" "5" "23"
1 "2019-10-11" "6" "34"
1 "2019-10-11" "7" "45"
1 "2019-10-12" "2" "30"
1 "2019-10-12" "4" "12"
1 "2019-10-12" "5" "23"
end
However, the panel data is not balanced because on the date "2019-10-12", there is no consumer 1,3,6,7 etc. What I want is to change the dataset to the below form, where the unbalanced data can be balanced and put the value P for the added ones as 0 and replicate the value of a for corresponding ids:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float P str10 order_date str2(id a)
1 "2019-10-11" "1" "20"
1 "2019-10-11" "2" "30"
1 "2019-10-11" "3" "34"
1 "2019-10-11" "4" "12"
1 "2019-10-11" "5" "23"
1 "2019-10-11" "6" "34"
1 "2019-10-11" "7" "45"
0 "2019-10-12" "1" "20"
1 "2019-10-12" "2" "30"
0 "2019-10-12" "3" "34"
1 "2019-10-12" "4" "12"
1 "2019-10-12" "5" "23"
0 "2019-10-12" "6" "34"
0 "2019-10-12" "7" "45"
end
Please let me know if you have any idea how to achieve this in Stata. Thanks a lot!