Hello,
I have a panel and need to transform it from Long to Wide. A string variable, countrycode, where that is the 3-letter ISO country code names appears. After putting everything into wide, all variables must be renamed by adding the countrycode 3-letter ISO country code before the variable's name.
Something like :
Data are for almost 80 years for 100 countries for about 200 variables. In the example below from my data, I am just reporting three countries and only three variables. Data contain gaps or even not observation for a particular variable for some counties, What I want it should be something like this :
I could do it with repeated pasting in the data, but I have more than 100 countries for 200 variables, so I am thinking a loop may be useful.
Furthermore, it would be nice if the new variables could maintain their origin label
Thank you for any help you could provide
[CODE]
I have a panel and need to transform it from Long to Wide. A string variable, countrycode, where that is the 3-letter ISO country code names appears. After putting everything into wide, all variables must be renamed by adding the countrycode 3-letter ISO country code before the variable's name.
Something like :
Code:
countrycode_varname
Data are for almost 80 years for 100 countries for about 200 variables. In the example below from my data, I am just reporting three countries and only three variables. Data contain gaps or even not observation for a particular variable for some counties, What I want it should be something like this :
Code:
ts FRA_cpi FRA_u FRA_education DEU_cpi DEU_u DEU_education GBR_cpi GBR_u GBR_education USA_cpi USA_u USA_education.
I could do it with repeated pasting in the data, but I have more than 100 countries for 200 variables, so I am thinking a loop may be useful.
Furthermore, it would be nice if the new variables could maintain their origin label
Thank you for any help you could provide
[CODE]
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id ts) str97 country str3 countrycode float(cpi u education) 1 2001 "France" "FRA" 1.6347808 8.61 . 1 2002 "France" "FRA" 1.9234123 8.7 . 1 2003 "France" "FRA" 2.098472 8.31 . 1 2004 "France" "FRA" 2.1420896 8.91 55.69758 1 2005 "France" "FRA" 1.7458694 8.49 56.59061 1 2006 "France" "FRA" 1.6751245 8.45 . 1 2007 "France" "FRA" 1.487998 7.66 59.42295 1 2008 "France" "FRA" 2.812862 7.06 60.34956 1 2009 "France" "FRA" .08762048 8.74 60.42087 1 2010 "France" "FRA" 1.5311227 8.87 61.89888 1 2011 "France" "FRA" 2.111598 8.81 62.77157 2 2001 "Germany" "DEU" 1.983857 7.77 . 2 2002 "Germany" "DEU" 1.4208056 8.48 . 2 2003 "Germany" "DEU" 1.0342277 9.78 . 2 2004 "Germany" "DEU" 1.6657335 10.73 78.48408 2 2005 "Germany" "DEU" 1.5469097 11.17 77.62368 2 2006 "Germany" "DEU" 1.5774282 10.25 77.84647 2 2007 "Germany" "DEU" 2.2983418 8.66 79.11421 2 2008 "Germany" "DEU" 2.628382 7.52 80.16417 2 2009 "Germany" "DEU" .3127376 7.74 80.61875 2 2010 "Germany" "DEU" 1.1038091 6.97 81.12799 2 2011 "Germany" "DEU" 2.0751746 5.82 81.72286 3 2001 "United Kingdom" "GBR" 1.5323496 4.7 . 3 2002 "United Kingdom" "GBR" 1.5204024 5.04 . 3 2003 "United Kingdom" "GBR" 1.3765004 4.81 . 3 2004 "United Kingdom" "GBR" 1.3903975 4.59 . 3 2005 "United Kingdom" "GBR" 2.0891366 4.75 . 3 2006 "United Kingdom" "GBR" 2.455662 5.35 . 3 2007 "United Kingdom" "GBR" 2.3865614 5.26 . 3 2008 "United Kingdom" "GBR" 3.5214086 5.62 . 3 2009 "United Kingdom" "GBR" 1.9617318 7.54 84.67217 3 2010 "United Kingdom" "GBR" 2.492655 7.79 86.42583 3 2011 "United Kingdom" "GBR" 3.8561125 8.04 86.08344 4 2001 "United States" "USA" 2.826171 4.73 . 4 2002 "United States" "USA" 1.5860317 5.78 . 4 2003 "United States" "USA" 2.2700949 5.99 . 4 2004 "United States" "USA" 2.677237 5.53 85.15315 4 2005 "United States" "USA" 3.392747 5.08 85.19178 4 2006 "United States" "USA" 3.225944 4.62 85.72323 4 2007 "United States" "USA" 2.8526726 4.62 . 4 2008 "United States" "USA" 3.8391004 5.78 86.61413 4 2009 "United States" "USA" -.3555463 9.25 86.70908 4 2010 "United States" "USA" 1.6400435 9.63 87.14941 4 2011 "United States" "USA" 3.1568415 8.95 87.59089 end
Comment