楼主: daming3775
14414 8

[回归分析求助] 求助:工具变量分位数回归 [推广有奖]

  • 6关注
  • 9粉丝

高级会员

学科带头人

53%

还不是VIP/贵宾

-

威望
0
论坛币
7507 个
通用积分
32.7653
学术水平
22 点
热心指数
35 点
信用等级
17 点
经验
27079 点
帖子
685
精华
0
在线时间
3656 小时
注册时间
2004-11-19
最后登录
2024-4-21

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
夸克版主在https://bbs.pinggu.org/forum.php?mod=viewthread&tid=1576402&highlight=ivqr里面贴的命令我执行不了,错误提示为(error occurred while loading ivqreg.ado),不知哪位达人能够提供该命令,谢谢!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:分位数回归 工具变量 分位数 highlight occurred 工具

本帖被以下文库推荐

沙发
daming3775 发表于 2012-10-24 16:36:52 |只看作者 |坛友微信交流群
命令在此:
*! ivqreg version DowonKwak 1.0.0 28July2010
program define ivqreg, eclass byable(onecall)
        version 10.1

        if _by() {
                local BY `"by `_byvars'`_byrc0':"'
        }
        if replay() {
                if ("`e(cmd)'"!="myprog") error 301

                Replay `0'
                exit
        }
        `BY' Estimate `0'
end

program Estimate, eclass byable(recall) sort

local cmdline `"ivqreg `0'"'

* step 1: parsing
gettoken lhs 0 : 0

gettoken p 0 : 0, parse(" (") quotes
while `"`p'"' != "(" {
        local inexog `"`inexog' `p'"'
        gettoken p 0 : 0, parse(" (") quotes
}

gettoken q 0 : 0, parse(" =") quotes
while `"`q'"' != "=" {
        local endo `"`endo' `q'"'
        gettoken q 0 : 0, parse(" =") quotes
}

gettoken r 0 : 0, parse(" )") quotes
while `"`r'"' != ")" {
        local instr `"`instr' `r'"'
        gettoken r 0 : 0, parse(" )") quotes
}

local allinstr `"`inexog' `instr'"'
local rhs `"`endo' `inexog'"'

* step 2: Syntax

local options "Level(cilevel)"
        syntax [if] [in] [,                ///
        `options'                          ///
         noConstant                        ///
         Quantil(real 0.5)                 ///
         Robust                            ///
         * ]
                if "`constan'"!="" {
                        di in red "nocons invalid"
                        exit 198
                }
                if `quantil' >= 1 {
                        local quant = `quantil'/100
                }
                else    local quant "`quantil'"
                if `quant' <= 0 | `quant' >= 1 {
                        di in red "quantiles(`quantil') out of range"
                        exit 198
                }
       
        /* count what is left over after marking out sample             */
        cap count if `touse'
        local N = r(N)
        if (`N' == 0) error 2000

* Step 3: Initial Two stage quantile regression for construnction of grid
marksample touse
markout `touse' `lhs' `endo' `instr' `inexog' `allinstr' `rhs'

qui regress `endo' `allinstr' if `touse'
predict dhat, xb
local dhat dhat
keep if `touse'

display _newline "Initial Estimation: `quantil'th Two Stage Quantile Regression" _col(60) "Number of obs = " e(N)
qui qreg `lhs' `dhat' `inexog' if `touse', q(`quantil')
predict iner if `touse', resid
matrix btwo=e(b)
scalar bdht=btwo[1,1]
matrix vtwo=e(V)
local vnames `endo' `inexog' _cons
matrix rownames vtwo = `vnames'
matrix colnames vtwo = `vnames'
matrix colnames btwo = `vnames'
ereturn post btwo vtwo, depname(`lhs') obs(`e(N)') esample(`touse')
ereturn display

display _newline in yellow "Grid search is in progress (200)"

marksample touse
markout `touse'
tempname intv nn nz dh_se

mata: ivqr_initial("`lhs'", "`endo'", "`inexog'", "`instr'", "`dhat'", "iner", "`touse'")
drop iner
local nz nz
local nn nn

*set of grid
scal dh_se=sqrt((`nn'/100)*intv[1,1])
scal gll=bdht-2*dh_se
scal size=dh_se/50
matrix gr_alpha=J(200,2,.)
       
forvalues j=1/200 {
matrix gr_alpha[`j',1]=gll+`j'*size
}  

* step 3: Grid search               
forvalues j=1/50 {
        gen yo`j'k=`lhs'-`endo'*gr_alpha[`j',1]
        qui qreg yo`j'k `instr' `inexog' if `touse', q(`quantil')
        matrix b_al`j'l=e(b)
        predict er`j', resid
        display _col(`j') _continue .
}
display _col(52) 50

forvalues j=51/100 {
        gen yo`j'k=`lhs'-`endo'*gr_alpha[`j',1]
        qui qreg yo`j'k `instr' `inexog' if `touse', q(`quantil')
        matrix b_al`j'l=e(b)
        predict er`j', resid
        local k= `j'-50
        display _col(`k') _continue .
}

display _col(52) 100


forvalues j=101/150 {
        gen yo`j'k=`lhs'-`endo'*gr_alpha[`j',1]
        qui qreg yo`j'k `instr' `inexog' if `touse', q(`quantil')
        matrix b_al`j'l=e(b)
        predict er`j', resid
        local k= `j'-100
        display _col(`k') _continue .
}

display _col(52) 150

forvalues j=151/200 {
        gen yo`j'k=`lhs'-`endo'*gr_alpha[`j',1]
        qui qreg yo`j'k `instr' `inexog' if `touse', q(`quantil')
        matrix b_al`j'l=e(b)
        predict er`j', resid
        local k= `j'-150
        display _col(`k') _continue .
}

display _col(52) 200


* step 4: IV quantile regression                
forvalues j=1/200 {
marksample touse
markout `touse'
tempname vq
matrix b_gam=b_al`j'l[1,1..`nz']
mata: ivqr_grid("yo`j'k", "`endo'", "`inexog'", "`instr'", "er`j'", "`touse'")
matrix gr_alpha[`j',2] = vq
drop yo`j'k er`j'
                  }

        svmat gr_alpha, name(a_grid)       
        gsort a_grid2
        scal alpha_opt=a_grid1          
        drop a_grid1 a_grid2

* step 5: Standard errors for just-identified case
if `nz'==1 {      
   gen double yoptm = `lhs'-`endo'*alpha_opt
   qui qreg  yoptm  `instr' `inexog' if `touse', q(`quantil')
   matrix xzhat=e(b)
   matrix xhat=xzhat[.,`nz'+1...]
   qui predict ero, resid
   qui iqreg ero
   matrix iqrr=e(b)
   qui sum ero
   scal eeh = r(sd)               
   scal iqq = iqrr[1,1]/1.349
   scal iqr = min(iqq,eeh)
   matrix bhat=(alpha_opt, xhat)                                                        
   *This is the final estimate for theta
   matrix colnames bhat = `endo' `inexog' _cons

marksample touse
markout `touse'
tempname Vrb vn
mata: ivqr_rbstse("yoptm", "`endo'", "`inexog'", "`instr'", "ero", "`touse'")
drop ero dhat yoptm       
}       

* step 5-2: Standard errors for over-identified case
if `nz'>1 {

   gen double yoptm = `lhs'-`endo'*alpha_opt
   qui qreg  yoptm  `instr' `inexog' if `touse', q(`quantil')
   matrix xzhat=e(b)
   matrix xhat=xzhat[.,`nz'+1...]
   qui predict ero, resid
   qui iqreg ero
   matrix iqrr=e(b)
   qui sum ero
   scal eeh = r(sd)               
   scal iqq = iqrr[1,1]/1.349
   scal iqr = min(iqq,eeh)                       
   matrix bhat=(alpha_opt, xhat)                                                        
   *This is the final estimate for theta
   matrix colnames bhat = `endo' `inexog' _cons


marksample touse
markout `touse'
tempname Vrb vn
mata: ivqrovi_rbstse("yoptm", "`endo'", "`inexog'", "`instr'", "ero", "`touse'")

drop ero dhat yoptm
}       

* step 6: return saved results
*// row and column names
local vnames `endo' `inexog' _cons
matrix rownames vn = `vnames'
matrix colnames vn = `vnames'
matrix rownames Vrb = `vnames'
matrix colnames Vrb = `vnames'
matrix colnames bhat = `vnames'

*// robust standard error option
local N = r(N)
if "`robust'" !="" {
        ereturn post bhat Vrb, depname(`lhs') obs(`N') esample(`touse')
       
                   }
        else    ereturn post bhat vn, depname(`lhs') obs(`N') esample(`touse')
                 
                  
*// Return as e() macro
ereturn local depvar ="`lhs'"
ereturn scalar N = r(N)
ereturn local cmdline `cmdline'
ereturn local title "Instrumental Variable `quantil'th Quantile Regression"
ereturn local cmd "ivqreg"

display _newline "`quantil'th Instrumental Variable Quantile Regression" _col(60) "Number of obs = " e(N)
ereturn display

end

使用道具

藤椅
h3327156 发表于 2012-10-24 21:26:09 |只看作者 |坛友微信交流群
我个人建议您改采
指令ivqte,您findit ivqte即可
The Stata Journal (2010) 10, Number 3, pp. 423–457
"Estimation of quantile treatment effects with Stata"

它和ivqreg很像的,有几个文献和ivqreg很像。

您参考一下,不过不要继续问我问题,哈! 我当年为了那个card的资料弄好久。
【为演练该paper的程序,找挺久,它和Wooldridge或Greene书上常见的card资料不太一样,
有兴趣您可以试试看】

本版先前有一些ivqte讨论,您可以参考一下。【当年我参与一下,不过现在忘地差不多了!】
https://bbs.pinggu.org/thread-1142360-1-1.html
已有 3 人评分学术水平 热心指数 信用等级 收起 理由
日新少年 + 1 + 1 + 1 精彩帖子
sunkai_bick + 1 + 1 观点有启发
daming3775 + 1 + 1 非常感谢

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 1   查看全部评分

使用道具

板凳
geokaran 发表于 2013-3-14 00:12:25 |只看作者 |坛友微信交流群
good

使用道具

报纸
122595877 发表于 2014-12-27 10:30:37 |只看作者 |坛友微信交流群
楼主的问题解决了么? 我也遇到同样问题。

使用道具

地板
mr_lu 发表于 2016-5-25 20:29:09 |只看作者 |坛友微信交流群
h3327156 发表于 2012-10-24 21:26
我个人建议您改采
指令ivqte,您findit ivqte即可
The Stata Journal (2010) 10, Number 3, pp. 423–457 ...
请问老师:如果内生变量是连续型变量而不是binary型变量,则ivqte似乎不可用。那么有什么替代的stata指令用于工具变量分位数回归吗?谢谢

使用道具

7
beiluo08 学生认证  发表于 2017-1-14 20:43:51 |只看作者 |坛友微信交流群
mr_lu 发表于 2016-5-25 20:29
请问老师:如果内生变量是连续型变量而不是binary型变量,则ivqte似乎不可用。那么有什么替代的stata指令 ...
没说不行啊。
   ivqte computes the quantile treatment effects (QTEs) of a binary variable using a weighting strategy.  This command can estimate both conditional and unconditional QTEs under either exogeneity or endogeneity.

使用道具

8
宛如青空 发表于 2019-3-2 20:54:03 |只看作者 |坛友微信交流群
请问ivqte只能得到第一步倾向得分的估计,如何得到第二步系数和显著性呢

使用道具

9
毫分7 发表于 2020-3-30 10:59:24 |只看作者 |坛友微信交流群
h3327156 发表于 2012-10-24 21:26
我个人建议您改采
指令ivqte,您findit ivqte即可
The Stata Journal (2010) 10, Number 3, pp. 423–457 ...
findit ivqte后,为什么用不了呢

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 03:14