Ⅰ 用stata做上市公司的面板數據固定效應,其中兩個自變數系數特別大,是什麼問題。
那就去對數再試試看
Ⅱ 請教,stata 如何定義時間序列 股票交
reg y x1 x2 x3predict e,r就可以生成變數命為e的殘差
Ⅲ STATA里處理時間的問題
gen year1=substr(v1,1,4)
gen month1=substr(v1,6,2)
以上兩條命令是將時間的年份和月份的字元提取出來
之後用real 函數將其轉換為 數字。。
比如 gen year=real(year1)
gen month=real(month1)
在之後
gen time=year*100+month
即可!
仔細琢磨一下,很簡單的~~
Ⅳ 請教,stata 如何定義時間序列 股票交易日
用tsset就可以了。
Ⅳ stata怎麼剔除年度行業數據低於15個的上市公司
del if 命令就可以了
Ⅵ 在stata中怎麼計算當年收入和上一年收入的差額
做一個計算就可以了啊
Ⅶ stata對企業前幾年的數據求最小二乘法
5年.
Ⅷ 定量分析是什麼,用stata軟體分析融資結構的影響因素之間的相關關系屬於定量分析嗎
定量分析是與定性分析相對應。舉個例子,定性分析是指教育能夠增加收入。定量分析是指,每增加一年教育,收入會增加1000元。話糙理不糙。。大概就是這個道理
Ⅸ stata怎麼做時間序列
//lecture 9
//繪值散點圖並添加圖例:
scatter le year, c(l) xlabel(1990 1918 1940(20)2000, grid) legend(on)
//顯示圖例(自帶的label,並未修改)
//le 變數的標簽 圖例是變數的標簽,所以修改圖例可以先修改標簽
//不改變真正的label
scatter le_male le_female year, c(l) legend(label(1 "Male") label(2 "Female"))
//繪值le_m、le_f 散點圖並添加圖例,將圖例分別改成「male」and「female」
scatter le_male le_female year, c(l) legend(on order(1 "male" 2 "female"))
//和上一行一樣
twoway (line le_male year, lpattern(dash)) (line le_female year, lcolor(red) lpattern(dot)) (line le_w year, lcolor(green)), legend (on order(1 "Male" 2 "Female" 3 "White") col(1) ring(0) pos(4) title("標題") subtitle("子標題"))
//twoway(將幾張圖畫在同一個裡面):展示第一個圖是什麼(),第二是什麼()第三個是什麼。。。。。,用括弧的形式展示出這個圖形是什麼,lpattern是線的形式 dash是虛線 (默認為實線),dot是點,lcolor是線的顏色
//其中pattern必須改 因為列印出黑白分不清顏色
//pos(4)是把圖例放在四點鍾方向(右下角)默認為六點鍾方向, ring(0)是放在圖形裡面 col()是一行放幾個元素
sysuse "auto.dta",clear
scatter mpg weight
//散點圖
twoway(scatter mpg weight if foreign == 0)(scatter mpg weight if foreign == 1) , legend(on order(1 "國產車" 2 "進口車"))
scatter mpg weight, by(foreign)
//以foreign,domestic作區分 與twoway不同,這個是分別獨立做圖 散點圖
scatter mpg weight, by(foreign, total)
//並添加一張包含所有觀測值
scatter mpg weight, by(foreign, total rows(1))
//將繪制的圖形改為一行排列
scatter mpg weight, by(foreign, total holes(3))
//將繪制圖形的留白放在左下方
scatter mpg weight, by(foreign,total title("My Title"))
//將圖形添加一個全標題
scatter mpg weight, subtitle(" ") by(foreign, total title("my title"))
//將每個小圖的標題去掉
scatter mpg weight, subtitle(ring(0) pos(12) nobexpand) by(foreign, total title("my title"))
//將每個圖的小標題位置更改
//如果foreign變數沒有標簽怎麼辦?
label drop origin
scatter mpg weight, by(foreign, total title("My Title"))
label define origin_v 0 "國產" 1 "進口"
label values foreign origin_v
scatter mpg weight, by(foreign, total title("My title"))
twoway (scatter mpg weight if foreign == 0) (scatter mpg weight if foreign == 1, msymbol(x)),legend(order(1 "國產" 2 "進口"))
scatter mpg weight || lfit mpg weight , by(foreign, row(1))
//繪制散點和線性復合圖形,根據foreign分組,添加一個總體圖 排成一行
scatter mpg weight || lfit mpg weight, legend(cols(1) ring(0)) by(foreign, legend(pos(4)))
//將圖例變為一列顯示,放置四點鍾方向
scatter mpg weight || lfit mpg weight ||,legend(rows(1)) by(foreign, total legend(at(3) pos(0)))
//將圖例放在2x2的留白處
scatter mpg weight || lfit mpg weight ||, by(foreign, total legend(off))
//將圖例放在2x2的留白處
//scheme選項
help scheme
//軸線選擇選項
help axis_choice_options
//example
sysuse auto,clear
scatter mpg price weight
//繪制散點圖,要求兩個y軸變數共用y軸
twoway (scatter mpg weight) (scatter price weight)
//一樣
twoway (scatter mpg weight) (scatter price weight, yaxis(2))
//繪制散點圖,並使用兩個y軸
twoway ( scatter mpg weight ) (scatter price weight, yaxis(2)), xlabel(1000(500)5000) ytick(#10, axis(2)) ylabel(#8, axis(1))
//每一個坐標軸添加刻度和標識,x軸大約10個刻度,左邊的y軸大約8個刻度,右邊的大約10個刻度
//添加軸線選項
help added_line_options
//圖形保存選項
sysuse auto,clear
help area
sysuse gnp96, clear
graph twoway area d.gnp96 date
//時間序列數據
gen dev_gnp = gnp96 - l.gnp96
twoway(line gnp96 date) (area d.gnp96 date, yaxis(2))
twoway(line gnp96 date) (area dev_gnp date, yaxis(2))
twoway(line gnp96 date) (line dev_gnp date, lpattern(dot) lcolor(1))
//繪制如下復雜圖:
graph use area_gnp
sysuse gnp96,clear
#delimit ;
twoway area d.gnp96 date, xlabel(#20, angle(90))
ylabel(-100(50)200,angel(0))
ytitle("Billions of 1996 Dollars")
xtitle("")
subtitle("Change in US GNP",pos(11))
note("Source: US Department of Commerce, Bureau of Economics")
;
#delimit cr
//換行功能換回回車
graph save area_gp, replace
//lecture 10
sysuse lifeexp, clear
help histogram
//直方圖📊,主要繪制連續變數,密度圖,還要乘以寬度才是頻數
twoway histogram le
//le是lexp的簡稱,直方圖描述從多少到多少有多少個
//by 在有0,1變數時候可以用
twoway hist le, bin(10)
twoway hist le, bin(5)
//設置幾個柱子
twoway hist le, width(5)
//設置柱子的寬度
twoway hist le, gap(10)
//柱子之間的間隙
twoway hist le, horizontal
//橫過來,水平直方圖
twoway hist le, percent
//以百分比形式顯示
help graph bar
help graph hbar
//條圖,主要繪制離散變數
sysuse citytemp, clear
graph bar (mean) tempjuly tempjan
graph bar tempjuly tempjan, over(region)
//默認設置為均值,按照地區(東南西北)劃分
graph bar tempjuly tempjan, over(region) bargap(30)
//兩個柱狀之間的位置可以調,可以重疊,也可以分開一點 -30代表重疊 30代表分開
graph bar tempjuly tempjan, over(region) stack
//可以把兩個變數堆積在一起,一般堆積的是個數 均值沒啥意義
graph bar tempjuly tempjan, over(division)
//數據中有兩個分類變數,可以根據division再分類
tab division if region == 1
tab division if region == 2
graph bar tempjan, over(division) over(region)
//每一個region下又分幾個division
graph bar tempjuly tempjan, over(region, gap(10))
//條與條之間的間隔
graph bar tempjuly tempjan, over(region, descending)
//數據中west是4 所以按4321排列
graph bar tempjuly tempjan, by(region)
//按region分別繪制四個圖
//圖形保存選項:
sysuse auto,clear
scatter mpg price weight
graph save fig1, replace
graph use fig1
//讀取已存儲圖形
graph export fig1.png, replace
//運行時要保證scatter mpg price weight 這個圖是打開的 否則運行不了
cd /Victor/stata
//電子地圖:
findit spmap
help spmap
unicode encoding set gb18030
unicode translate "china_label.dta"
//必須先清零數據,然後運行一遍路徑名 才能運行這兩行命令
use "china_label.dta", clear
//example 1
use china_label, clear
gen xx = uniform()
spmap xx using "china_map.dta", id(id) title("中國地圖",size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..)
//clnumbers 代表8種不同的綠色
//example 2
tab name
replace name = subinstr(name, "省", "", .)
replace name = subinstr(name, "市", "", .)
replace name = subinstr(name, "回族自治區", "", .)
replace name = subinstr(name, "壯族自治區", "", .)
replace name = subinstr(name, "特別行政區", "", .)
replace name = subinstr(name, "自治區", "", .)
replace name = subinstr(name, "維吾爾", "", .)
tab name
//改名字
foreach x of numlist 1/5{
gen num`x'=uniform()
}
//產生0到1的隨機數
format x %9.3g
foreach x of numlist 1/5{
spmap `x' using "china_map.dta",id(id) title("中國地圖", size(*0.8)) label(label(ename) xcoord(x_coord) ycoord(y_coord) size(*.8)) plotregion(icolor(stone)) graphregion(icolor(stone)) fc(Greens) clnumber(8) oc(white ..) osize(medthin ..) graph export "china0`x'.png", replace
}
//lecture 11
sysuse auto, clear
summarize mpg weight
//summarize 後面可以接一個或多個變數,個數 均值 最小最大值
summarize mpg, detail
//會有關於數據其他的統計指標
help summarize
tabulate mpg, sort
//離散變數排序之後用表統計
tabulate foreign
//最好是分類變數去tabulate,展示各個種類有多少個,佔多大比例(離散的)
help tabulate
sysuse nlsw88, clear
tab occ
//不同職業的樣本在我的資料庫裡面分別有多少個,比例大小,總的樣本數量是多少
tab instry
sysuse auto, clear
tabstat mpg price weight rep78 , stat(n mean sd min median max) c(s)
//c(s)是轉置過來這個矩陣,默認閱讀方式是:列是統計指標,行是變數名稱
help tabstat
//下劃線是代表可以簡寫,只寫c(s)
//可以規定format 總長度多少個單位,小數點前面,後面有多少個單位,統一成一個格式
tabstat mpg price weight rep78 , by(foreign) stat(n mean sd min median max) c(s)
//by是以什麼分類展示
//輸出表格(不要復制):
ssc install logout
logout, save(summarize) tex word excel dec(3) replace: tabstat mpg price weight rep78 , stat(n mean sd min median max) column(s) long format
//不建議導出成tex word 因為在Excel還要進一步編輯,xml格式的可以在excel打開 rtf是可以從word打開 就可以應用在論文裡面了。replace替換原來的 dec(3)代表小數點後統一保留三位數,replace後面與之前一模一樣 ,column是列
logout, save(summarize) tex word excel dec(3) replace: tabstat mpg price weight rep78 , by(foreign) stat(n mean sd min median max) c(s)
//save(文件名)
use nei_sample.dta, clear
describe
plicates tag newid year, gen(p)
edit newid year if p >= 195
plicates drop newid year, force
help merge
plicates drop newid year, force
//一個地方會有n個企業
merge m:1 fips year using "county_na.dta"
//根據county的代碼和時間調用
//有三部分的merge,merge=1和2是不需要的地方 只保留3(matched) 因為沒有企業的觀測值(0),而merge=1則是有企業的觀測值(1),而merge=2沒有政策的觀測值(0)(觀測到了企業污染,卻沒有觀察到關於政策的變數)
//我們關心企業所在的地區是否有環境政策
//做一個最簡單的回歸,政策對污染的影響:(regress)
foreach v of varlist reg_* {
replace `v'= 0 if `v' == .
}
//將missing變成0
reg co reg_co
gen lco = ln(co)
reg lco reg_co
//有0的問題
//add a set of mmies(虛擬變數), tear , instry, county
gen fips_st = substr(fips,1,2)
//state(截取fips編號的前兩位)
gen sic2 = substr(sic,1,2)
//instry
gen sic1 = substr(sic2,1,1)
keep if sic1 == "2" | sic1 == "3"
//manufacturing only 或
gen lco = log(co)
//generate log
reg lco reg_co
//reg_co代表政府有無監管,有就是1(非常不準)表中的_cons代表截距
xi: reg lco reg_co i.year
//按照年份,每年加一個虛擬變數,是這一年就是一
//with year FE (根據每一年不一樣回歸 )
//年份前的系數是相對於基年的增加或減少,添加年份虛擬變數
//分離出宏觀經濟沖擊的影響
bys year: egen id_sum = count(newid)
//?
xi : reg lco reg_co id_sum i.year
//with year FE, multicolinearity
//如果觀測值是1996年的,那麼iyear1996=1,這個統一的因素會影響所有的企業(宏觀經濟因素,所有企業都受影響),今年的這個企業和明年的這個企業外部環境是不一樣的,是什麼不重要,要capture這個東西
xi : reg lco reg_co i.year i.sic2
//with instry FE(不同產業的影響)
xi : reg lco reg_co i.year i.sic2 i.fips_st
//with state FE(省政府對環境保護的壓力的影響)
xi : reg lco reg_co i.year i.sic2 i.fips
//with county FE
plicates drop newid year, force
xtset newid year
//set panel
xi: reg lco reg_co i.newid
//通過添加mmy
xi: xtreg lco reg_co, fe
//先進行差分 (常用)
//這兩行的結果相同
xi: xtreg lco reg_co i.year , fe
//year
xi: xtreg lco reg_co i.year i.fips_st, fe
//state fe
xi: xtreg lco reg_co i.year i.sic2, fe
//instry fe
//下標都是固定效益 用希臘字母帶下標 c是位置 j是行業 t為第t年的宏觀經濟形勢/技術進步(系統性) i表示企業自身的固定效益,是觀察不到的個體特徵因素(有些企業管理水平天生高,低)
sort newid sic2
by newid: gen newsic2 = sic2[_N]
xi: xtreg lco reg_co i.newsic2, fe
//企業不更改行業屬性
//two-way fised effects with firm fixed effects
xi:xtreg lco reg_co i.teay*i.newsic2, fe
//instry-year FE
xi:xtreg lco reg_co i.teay*i.fips_st, fe
findit outreg2
//默默地回歸quite
qui xi: xtreg lco reg_co i.newsic2,fe
outreg2 using result1.xls,excel keep(reg_co) dec(3) addtext(Firm FE, Y,Stata-Year FE,n,Instry-Year FE,n)
//keep只保留關心的系數,小數點後面保留多少位
//數據批量導入與導出,亂碼處理,變數構造,數據的整理,數據變數的修改,相互轉換
//數據可視化,在統計中summary statistic table 然後在fixeffect model 簡單地看了一下
//將回歸結果用excel報告
Ⅹ 如何用EVIEWS對300多家上市公司三年數據回歸
是面板數據吧,建立pool就行了