Hi, a relatively novice Stata user here, I've encountered problems with the reshape command. Specifically creating quarterly observations as a j variable in long format.
Here's an example of my dataset.
input int s_id byte c_id str23 filename str83 code indicator float(yr2014q1 yr2014q2)
1 1 "PSIFIs_IBD_Bahrain" "AD06 - Accommodation And Food Service Activities" 0 0
1 2 "PSIFIs_IBD_Brunei" "AD06 - Accommodation And Food Service Activities" 33.87 33.74
1 3 "PSIFIs_IBD_Indonesia" "AD06 - Accommodation And Food Service Activities" 60.58 70.81
1 4 "PSIFIs_B_Jordan" "AD06 - Accommodation And Food Service Activities" 6.91 3.39
1 6 "PSIFIs_IBD_Nigeria" "AD06 - Accommodation And Food Service Activities" 0 0
1 7 "PSIFIs_IBD_Oman" "AD06 - Accommodation And Food Service Activities" 0 0
1 8 "PSIFIs_IBD_Pakistan" "AD06 - Accommodation And Food Service Activities" 2.13 2.17
1 9 "PSIFIs_IBD_Saudi Arabia" "AD06 - Accommodation And Food Service Activities" 175.91 170.01
1 10 "PSIFIs_IBD_Sudan" "AD06 - Accommodation And Food Service Activities" 0 0
1 11 "PSIFIs_IBD_TUR" "AD06 - Accommodation And Food Service Activities" 0 0
1 12 "PSIFIs_IBD_UAE" "AD06 - Accommodation And Food Service Activities" 323.46 368.62
2 1 "PSIFIs_IBD_Bahrain" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 2 "PSIFIs_IBD_Brunei" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 3 "PSIFIs_IBD_Indonesia" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 .06
2 4 "PSIFIs_B_Jordan" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 6 "PSIFIs_IBD_Nigeria" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 7 "PSIFIs_IBD_Oman" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0
My ID variables include a country code (c_id) as well as a code for each variable (s_id).
The following problems I've encountered:
1. Do I declare my time variable as quarterly before using the command:
"reshape long yr, i[c_id s_id] j[year]"
I initially used year as it is a time variable that stata could recognise hoping to be able to declare the variables as quarterly after the reshaping, however,
2. Error "option i incorrectly specified" occurred
I also tried to follow a StataCorp video on YouTube, however, their data had stub names with each observation, following their advice the following error occurred:
no xij variables found
You typed something like reshape wide a b, i(i) j(j).
reshape looked for existing variables named a# and b# but could not find any. Remember
this picture:
long wide
+---------------+ +------------------+
| i j a b | | i a1 a2 b1 b2 |
|---------------| <--- reshape ---> |------------------|
| 1 1 1 2 | | 1 1 3 2 4 |
| 1 2 3 4 | | 2 5 7 6 8 |
| 2 1 5 6 | +------------------+
| 2 2 7 8 |
+---------------+
long to wide: reshape wide a b, i(i) j(j) (j existing variable)
wide to long: reshape long a b, i(i) j(j) (j new variable)
r(111);
Any advice would be appreciated.
Thank you!
Here's an example of my dataset.
input int s_id byte c_id str23 filename str83 code indicator float(yr2014q1 yr2014q2)
1 1 "PSIFIs_IBD_Bahrain" "AD06 - Accommodation And Food Service Activities" 0 0
1 2 "PSIFIs_IBD_Brunei" "AD06 - Accommodation And Food Service Activities" 33.87 33.74
1 3 "PSIFIs_IBD_Indonesia" "AD06 - Accommodation And Food Service Activities" 60.58 70.81
1 4 "PSIFIs_B_Jordan" "AD06 - Accommodation And Food Service Activities" 6.91 3.39
1 6 "PSIFIs_IBD_Nigeria" "AD06 - Accommodation And Food Service Activities" 0 0
1 7 "PSIFIs_IBD_Oman" "AD06 - Accommodation And Food Service Activities" 0 0
1 8 "PSIFIs_IBD_Pakistan" "AD06 - Accommodation And Food Service Activities" 2.13 2.17
1 9 "PSIFIs_IBD_Saudi Arabia" "AD06 - Accommodation And Food Service Activities" 175.91 170.01
1 10 "PSIFIs_IBD_Sudan" "AD06 - Accommodation And Food Service Activities" 0 0
1 11 "PSIFIs_IBD_TUR" "AD06 - Accommodation And Food Service Activities" 0 0
1 12 "PSIFIs_IBD_UAE" "AD06 - Accommodation And Food Service Activities" 323.46 368.62
2 1 "PSIFIs_IBD_Bahrain" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 2 "PSIFIs_IBD_Brunei" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 3 "PSIFIs_IBD_Indonesia" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 .06
2 4 "PSIFIs_B_Jordan" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 6 "PSIFIs_IBD_Nigeria" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0 0
2 7 "PSIFIs_IBD_Oman" "AD06 - Activities Of Extraterritorial Organisations And Bodies" 0
My ID variables include a country code (c_id) as well as a code for each variable (s_id).
The following problems I've encountered:
1. Do I declare my time variable as quarterly before using the command:
"reshape long yr, i[c_id s_id] j[year]"
I initially used year as it is a time variable that stata could recognise hoping to be able to declare the variables as quarterly after the reshaping, however,
2. Error "option i incorrectly specified" occurred
I also tried to follow a StataCorp video on YouTube, however, their data had stub names with each observation, following their advice the following error occurred:
no xij variables found
You typed something like reshape wide a b, i(i) j(j).
reshape looked for existing variables named a# and b# but could not find any. Remember
this picture:
long wide
+---------------+ +------------------+
| i j a b | | i a1 a2 b1 b2 |
|---------------| <--- reshape ---> |------------------|
| 1 1 1 2 | | 1 1 3 2 4 |
| 1 2 3 4 | | 2 5 7 6 8 |
| 2 1 5 6 | +------------------+
| 2 2 7 8 |
+---------------+
long to wide: reshape wide a b, i(i) j(j) (j existing variable)
wide to long: reshape long a b, i(i) j(j) (j new variable)
r(111);
Any advice would be appreciated.
Thank you!
Comment