Hello Statalisters!
I have a data formatting issue that leaves me sleepless for nights. I know it must be simple to solve but I simply have no idea.
In the dataset below (excerpt) I have 7 different "sanction types" imposed by countries/associations on various dates. Now, as I have a column for the sanction type, it is unnecessary to have 7 more columns with the sanction type that provides a "1" whenever that sanction type is imposed by the country on that date. I want to drop the column "sanction type" and collapse the rows, so that I have date-country-specific data, where in each row the sanction type is marked by a "1" in the respective column. In the same row!
I have following data:
and I wish to convert to:
-----------
I hope you see my point and I appreciate any help! Thank you!
Best regards Chris
I have a data formatting issue that leaves me sleepless for nights. I know it must be simple to solve but I simply have no idea.
In the dataset below (excerpt) I have 7 different "sanction types" imposed by countries/associations on various dates. Now, as I have a column for the sanction type, it is unnecessary to have 7 more columns with the sanction type that provides a "1" whenever that sanction type is imposed by the country on that date. I want to drop the column "sanction type" and collapse the rows, so that I have date-country-specific data, where in each row the sanction type is marked by a "1" in the respective column. In the same row!
I have following data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 date str14 country str10 sanctiontype byte(financial travel individual export import tradesupport nosanction) "2022-02-21" "United States" "financial" 1 . . . . "2022-02-21" "United States" "individual" . . . . . . . "2022-02-21" "United States" "import" . . . . 1 . . "2022-02-21" "United States" "export" . . . . . . . "2022-02-21" "European Union" "financial" 1 . . . . . "2022-02-21" "European Union" "individual" . . 1 . . . . "2022-02-21" "European Union" "travel" . . . . . . . "2022-02-22" "United States" "financial" 1 . . . . . . "2022-02-22" "United States" "individual" . . 1 . . . . "2022-02-22" "United Kingdom" "financial" 1 . . . . . . "2022-02-22" "United Kingdom" "individual" . . 1 . . . . "2022-02-22" "United Kingdom" "travel" . 1 . . . . . "2022-02-22" "Germany" "import" . . . . 1 . . "2022-02-23" "European Union" "financial" 1 . . . . . . "2022-02-23" "European Union" "individual" . . 1 . . . . "2022-02-23" "European Union" "import" . . . . 1 . . "2022-02-23" "European Union" "export" . . . 1 . . . end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 date str14 country byte(financial travel individual export import tradesupport nosanction) "2022-02-21" "United States" 1 . 1 1 . . . "2022-02-21" "European Union" 1 1 1 . . . . end
I hope you see my point and I appreciate any help! Thank you!
Best regards Chris
Comment