try:
/* if the data is like
var1 var2 var3
AAA . .
Period 2004 2005
var1 10 5
var2 20 10
var3 30 15
BBB . .
Period 2004 2005
var1 10 5
var2 20 10
var3 30 15
*/
gen company = var1 if var1!="Period" & substr(var1,1,3)!="var"
replace company=company[_n-1] if company==""
drop if company==var1 | var1=="Period"
preserve
drop var3
reshape wide var2, i(company) j(var1) string
tempfile f1
sort company
save `f1'
restore
drop var2
rename var3 var2
reshape wide var2, i(company) j(var1) string
tempfile f2
sort company
save `f2'
use `f1'
append using `f2'
sort company, stable
gen period=2005 if int(_n/2)==_n/2
replace period=2004 if period==.
order company period


雷达卡








京公网安备 11010802022788号







