Hello,
I would like to start by thanking the forum participants. I learned a lot here.
I want to build a panel data set. To manage my data, I have to deal with the following problem.
For the key variable, SEC, the original dataset recorded several observations in the same cell for a specific country - year. I need those observations to be in a separate row keeping all the other observations (country, year ....) the same.
There is a unique ID for each row. It would be ideal to create another unique ID for the new rows (but that is not the main concern now)
I have tried to split the observations into unique columns and then convert the data from wide format to long format (with the help of this discussion: https://www.statalist.org/forums/for...s-in-same-cell)
Unfortunately, I failed. I would appreciate it if you offer any help.
P.S: The original sector variable "SEC" was a string variable and I destringed it.
I would like to start by thanking the forum participants. I learned a lot here.
I want to build a panel data set. To manage my data, I have to deal with the following problem.
For the key variable, SEC, the original dataset recorded several observations in the same cell for a specific country - year. I need those observations to be in a separate row keeping all the other observations (country, year ....) the same.
There is a unique ID for each row. It would be ideal to create another unique ID for the new rows (but that is not the main concern now)
I have tried to split the observations into unique columns and then convert the data from wide format to long format (with the help of this discussion: https://www.statalist.org/forums/for...s-in-same-cell)
Unfortunately, I failed. I would appreciate it if you offer any help.
P.S: The original sector variable "SEC" was a string variable and I destringed it.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float year long(cty SEC) double ID 2009 1 16806 814422 2009 1 6604 653200578 2012 1 198 84481521203 2018 1 5595 369461773733 2012 1 7064 8448125978 2014 1 12184 90921701158 2013 1 5078 369172859 2017 1 15289 36943208613 2016 1 5078 11955912 2018 1 11945 369541585591 2017 1 16217 369381271124 2018 1 14941 304614261 2009 1 6604 110209654 2018 1 16360 319078768 2019 1 5094 43106924 2015 1 16859 38150319 2010 1 14491 36895145493 2013 1 16395 100368761 2012 1 5078 36963182202 2015 1 438 3695341102 end label values cty cty label def cty 1 "Austria", modify label values SEC SEC label def SEC 198 "012", modify label def SEC 438 "013", modify label def SEC 5078 "214", modify label def SEC 5094 "214, 013", modify label def SEC 5595 "214, 347, 463", modify label def SEC 6604 "222", modify label def SEC 7064 "235", modify label def SEC 11945 "345, 333, 120, 334, 335, 342, 346, 379, 414, 341, 352, 343, 351, 353, 232, 354, 483, 389, 344, 347, 369, 282, 019, 348, 362, 392, 361, 292, 317, 319, 321, 327, 322, 325, 326, 263, 265, 261, 266, 264, 355, 267, 279, 273, 272, 281, 448 > , 271, 295, 293, 296, 375, 373, 372, 371, 163, 382, 413, 411, 393, 412, 429, 433, 415, 421, 416, 431, 432, 439, 434, 445, 435, 444, 449, 452, 446, 443, 442, 451, 469, 472, 474, 473, 479, 476, 475, 471, 491, 492, 499, 494, 493, 482, 481, 447, 381, 465, > 385", modify label def SEC 12184 "347", modify label def SEC 14491 "369, 461", modify label def SEC 14941 "412", modify label def SEC 15289 "431", modify label def SEC 16217 "461, 473, 474, 385", modify label def SEC 16360 "465", modify label def SEC 16395 "471", modify label def SEC 16806 "713", modify label def SEC 16859 "965", modify
Comment