2 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
cd /Victor/stata
//二
//1.a
sysuse "auto.dta",clear
foreach num of numlist 1/74{
export excel using "auto`num'.xlsx" in `num'
}
//1.b
foreach num of numlist 1/74{
import excel "auto`num'", clear
save "auto`num'.dta", replace
}
//將excel轉(zhuǎn)換成dta格式
use "auto1.dta",clear
foreach num of numlist 2/70{
append using "auto`num'.dta"
}
save "auto_new.dta", replace
//1.c
foreach num of numlist 1/74{
erase "auto`num'.xlsx"
}
//2(因?yàn)槲业膕tata軟件無法識(shí)別跨行命令,只能一長(zhǎng)串寫在一行)
use "auto_new.dta",clear
twoway(scatter weight mpg if foreign == 0, mcolor(navy blue) msymbol(x)) (scatter weight mpg if foreign == 1, mcolor(red)) , legend(on order(1 "foreign" 2 "domestic") ring(0)) title("The Relatonship between Car Weight and MPG") ylabel(1000 2000 3000(2000)5000) xlabel(10(5)35)
//3
sysuse "nlsw88.dta",clear
tabstat wage hours ttl_exp tenure ,by(union) stat(n mean sd min median) c(s)
//4
sysuse "nlsw88.dta",clear
order wage hours ttl_exp tenure collgrad
foreach v of varlist wage-collgrad{
ttest `v',by(union)
}
//5
sysuse "nlsw88.dta",clear
reg wage age race industry occupation ttl_exp hours
ssc install logout
logout, save(result_2017302330037.xlsx) excel dec(3) replace:reg wage age race industry occupation ttl_exp hours
//三
sysuse "firm.dta",clear
sort ID date ipc patent_ID
//2
replace firm_name = subinstr(firm_name, "有限責(zé)任公司"," ",.)
replace firm_name = subinstr(firm_name, "集團(tuán)股份有限公司"," ",.)
replace firm_name = subinstr(firm_name, "股份有限公司"," ",.)
//3
//計(jì)算每個(gè)企業(yè)每年專利數(shù)量總和
use "firm.dta",clear
encode patent_ID ,gen(patent_ID1)
bys ID date : egen num_patent=count(patent_ID1)
//計(jì)算不重復(fù)的領(lǐng)域數(shù)
duplicates drop ID date ipc,force
bys ID date: egen ipc_sum=count(ipc)
添加回答
舉報(bào)