Dear Statalisters
I've a problem in renaming my variables in my dataset. My dataset consists of Credit-to-GDP gaps of 44 different countries around the world from 1999Q1 to 2017Q4. The data example shown below is a simplified version,where:
------------------ copy up to and including the previous line ------------------
Before reshaping the dataset from wide form to long form, I want to rename the variables beginning horizontally from Q1 till the last time period(say, in this case, Q4), i.e. renaming Q1 as "1999Q1",Q2 as "1999Q2",Q3 as "1999Q3" and so on.
But when I tried the following code,
rename Q1 1999Q1
Stata returned me an error message:
1 new variable name invalid
You attempted to rename Q1 to 1999Q1. That is an invalid
Stata variable name.
r(198);
end of do-file
r(198);
Does anyone have any ideas on how I could rename all of the time variables into the correct names in a faster way? What is wrong with my rename command?
Also, as an additional piece of information in my original dataset, the labels of the variables are right, i.e.label of Q1 is "1999-Q1", that of Q2 is "1999-Q2".
Thank you very much.
Many thanks
Keith
I've a problem in renaming my variables in my dataset. My dataset consists of Credit-to-GDP gaps of 44 different countries around the world from 1999Q1 to 2017Q4. The data example shown below is a simplified version,where:
- BORROWERS_CTY is the abbreviation of a borrowing country
- BORROWERS_CTYName is the name of a borrowing country
- Q1 should stand for Yr 1999, Quarter 1 (or 1999Q1;but somehow when I imported the data from the Excel file, the variable has been named as "Q1")
- Q2 similarly stands for 1999Q2; i.e. all numerical values under this column are Credit-to-GDP gaps of that country in Yr 1999 Q2.
- Q3 for 1999Q3
- Q4 for 1999Q4
- And so on other letters such as G,H, I ...(which represent 2000Q1,2000Q2 and 2000Q3 respectively; They aren't displayed here for simplicity)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str2 BORROWERS_CTY str14 BORROWERS_CTYName str5(Q1 Q2 Q3 Q4) "RU" "Russia" "" "" "" "" "CO" "Colombia" "" "" "" "" "XM" "Euro area" "" "" "" "" "GB" "United Kingdom" "-0.3" "1.5" "1.7" "3.3" "SG" "Singapore" "6.7" "6.1" "3.4" "2.5" "TH" "Thailand" "4.4" "-3.2" "-12.9" "-21.8" "IT" "Italy" "0.3" "3.3" "3.7" "6.2" "AU" "Australia" "0.1" "-0.7" "0.4" "2.1" "GR" "Greece" "5.6" "5.2" "5.9" "6.5" "NO" "Norway" "6" "6.6" "3" "1.2" "NZ" "New Zealand" "4.2" "3.2" "3.8" "5" "IN" "India" "-0.5" "-1.8" "-1.5" "-0.2" "IE" "Ireland" "17.5" "24" "25.4" "29.6" "HU" "Hungary" "" "" "" "7.7" "CN" "China" "6.2" "6.8" "7.4" "8.2" "SA" "Saudi Arabia" "" "" "" "" "CA" "Canada" "0.4" "0.1" "-2" "-5.5" "CL" "Chile" "20.9" "24.3" "24.5" "21.5" "ID" "Indonesia" "-18.1" "-36.4" "-31.6" "-37.5" "CH" "Switzerland" "-9" "-6.5" "-5.1" "-6.7" "PT" "Portugal" "23.1" "27.2" "28.4" "30" "DE" "Germany" "3.7" "4.9" "5.8" "7.4" "PL" "Poland" "" "" "" "" "IL" "Israel" "" "" "" "" "AR" "Argentina" "8.8" "8.8" "7.7" "7.1" "HK" "Hong Kong SAR" "-0.5" "-7.2" "-8.9" "-12" "TR" "Turkey" "1.6" "1" "0.9" "0.6" "FR" "France" "-5.5" "-3.3" "-2.5" "-1.1" "MY" "Malaysia" "11" "5.8" "3.3" "-5" "BR" "Brazil" "" "" "" "" "SE" "Sweden" "-4" "-4.5" "-4.8" "-1.3" "NL" "Netherlands" "6.1" "6.3" "7.7" "8.1" "BE" "Belgium" "14.9" "15.7" "17.4" "17.8" "CZ" "Czech Republic" "" "" "" "" "ES" "Spain" "12.1" "17.4" "17.5" "19" "DK" "Denmark" "0.9" "2.1" "1" "2.4" "JP" "Japan" "-24.3" "-25.7" "-25.5" "-22.2" "AT" "Austria" "-1.3" "-0.6" "2.3" "4.2" "ZA" "South Africa" "7.1" "6.8" "5.4" "4.5" "LU" "Luxembourg" "" "" "" "" "KR" "Korea" "10.4" "1" "-3.7" "-12.8" "FI" "Finland" "-21.5" "-18.1" "-18.2" "-18.9" "MX" "Mexico" "-10" "-10.3" "-12" "-12.3" "US" "United States" "1.2" "1.7" "3" "3.5" end
Before reshaping the dataset from wide form to long form, I want to rename the variables beginning horizontally from Q1 till the last time period(say, in this case, Q4), i.e. renaming Q1 as "1999Q1",Q2 as "1999Q2",Q3 as "1999Q3" and so on.
But when I tried the following code,
rename Q1 1999Q1
Stata returned me an error message:
1 new variable name invalid
You attempted to rename Q1 to 1999Q1. That is an invalid
Stata variable name.
r(198);
end of do-file
r(198);
Does anyone have any ideas on how I could rename all of the time variables into the correct names in a faster way? What is wrong with my rename command?
Also, as an additional piece of information in my original dataset, the labels of the variables are right, i.e.label of Q1 is "1999-Q1", that of Q2 is "1999-Q2".
Thank you very much.
Many thanks
Keith
Comment