全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 统计软件培训班VIP答疑区
1332 3
2011-08-16
我想做一个回归:Y = b0 + b1 * X1 + b2*X2 + b3*X3+e

但有两个限制条件:


1、b1+b2+b3 = 1
2、b1,b2,b3非负


请问是用stata如何实现?谢谢。


二维码

扫码加我 拉你入群

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

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

全部回复
2011-8-18 08:26:26
自己顶一下,急切盼望连老师的回复中,谢谢。
二维码

扫码加我 拉你入群

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

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

2011-8-18 11:10:51

*-Constrainted regression

*-https://bbs.pinggu.org/thread-1155288-1-1.html

/*  Question:

  我想做一个回归:Y = b0 + b1 * X1 + b2*X2 + b3*X3+e
  但有两个限制条件:

  1、b1+b2+b3 = 1
  2、b1,b2,b3非负

  请问是用stata如何实现?谢谢。
  
Treatment:
  For contraint 2, we can estimate ln(b) instead of b,
  once we get the esimator of ln(b), b can be recovered as b=exp(ln(b)),
  which ensure b is positive.
  
  With constraint 1, only two parameters remian, say, b3=1-b1-b2
  
  NLS can be used to get the estimations of b1, b2, and b3
*/

  clear
  set obs 1000
  
  gen x1 = 2*invnorm(uniform())
  gen x2 = 3*invnorm(uniform())
  gen x3 = 4*invnorm(uniform())
  gen e  = 1*invnorm(uniform())
  
  gen y = 10 + 0.2*x1 + 0.3*x2 + 0.5*x3 + e
  
  *-note: b0=10, b1=0.2, b2=0.3, b3=0.5
  
  
  *----
  *-OLS
  
    reg y x*
  
  *----
  *-NLS

  *-Only Constraints 2:  b1+b2+b3=1
        nl (y = {b0} + {b1}*x1 + {b2}*x2 + (1-{b1}-{b2})*x3)
          
  *-Both Constraints
        nl (y = {b0} + exp({b1})*x1 + exp({b2})*x2 + (1-exp({b1})-exp({b2}))*x3)
        local ln_b1 = _b[/b1]
        local ln_b2 = _b[/b2]
        dis in g "b1= " in y exp(`ln_b1')
        dis in g "b2= " in y exp(`ln_b2')
    dis in g "b3= " in y 1-exp(`ln_b1')-exp(`ln_b2')
二维码

扫码加我 拉你入群

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

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

2011-8-18 17:36:48
感谢连老师,多谢多谢。
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群