楼主: goaway2
10474 3

STATA计算相加模型交互作用的程序问题 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

小学生

42%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
39 点
帖子
4
精华
0
在线时间
9 小时
注册时间
2011-1-29
最后登录
2014-12-28

楼主
goaway2 发表于 2011-1-29 14:19:04 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
以下是用STATA计算相加模型交互作用指标 RERI 的95%CI的程序(从文献复制过来 的),但程序运行到最后的时候出现的错误提示:
41.
. } /* close forvalues loop */
invalid syntax
program error:  code follows on the same line as close brace
program error:  code follows on the same line as close brace
program error:  code follows on the same line as close brace
r(198);

本人对STATA了解甚少,请各位指点应该怎样纠正程序,谢谢!

原程序如下:
* obtain likelihood based CI limits *
***********************************
* initialize -2LL values
global LL = -2*e(ll)
global refLL = -2*e(ll)
* get interaction coefficient and standard error
matrix A = e(b)
global b3 = A[1,4]
matrix B = e(V)
global seb3 = sqrt(B[4,4])
* initialize other variables
global null = 0
global neglogl = 0
global diff = 0
global param = 0
global step = 0
global lcl = .
global ucl = .
* i = 1 for lower bound and i = 2 for upper bound
forvalues i = 1(1)2 {
         global conv = 0
         global step = $seb3
         global beta = $b3
         global num = 0

    while $conv == 0       {
         global num = $num + 1
    constraint define $num _b[eq2:inter]== $beta
         ml model lf linearodds (cons: ) (case = alcohol smoke inter, nocons),
constraint($num)
         ml init A, copy
         quietly ml maximize, difficult repeat(10)
         global LL = -2*e(ll)
         global diff = ($LL - $refLL)
         if ($diff >= 3.8413 & $diff <= 3.8415)  {
                 global conv = 1
                                   if (`i' == 1)    {
                                   global lcl = $beta
                                                             }
                                   if (`i' == 2)    {
                                   global ucl = $beta
                                                             }
                                           }
                 if ($diff >= 3.8415)  {
                                   if (`i' == 1)    {
                                   global beta = ($beta + $step)
                                                             }
                                   if (`i' == 2)    {
                                   global beta = ($beta - $step)
                                                             }
                                   global step = ($step * 0.5)
                                                }
    disp $num, "null =", %8.4f $refLL," ","neglogl =", %8.4f $LL," ", "diff =", /*
    */   %6.4f $diff," ","step =", %6.4f $step," ","b3 =", %6.4f $beta
                                   if (`i' == 1)    {
                                   global beta = ($beta - $step)
                                                             }
                                   if (`i' == 2)    {
                                   global beta = ($beta + $step)
                                                             }
                                      } /* close of while loop */
} /* close forvalues loop */
disp "-------------------------------------------------------------------------------"
disp "The likelihood based 95% CI limits are:", %6.4f $lcl,",",%6.4f $ucl
二维码

扫码加我 拉你入群

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

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

关键词:Stata 交互作用 tata coefficient interaction 程序 模型 Stata 交互作用 相加

沙发
dxystata 发表于 2011-2-6 09:46:43
goaway2 发表于 2011-1-29 14:19
以下是用STATA计算相加模型交互作用指标 RERI 的95%CI的程序(从文献复制过来 的),但程序运行到最后的时候出现的错误提示:
41.
. } /* close forvalues loop */
invalid syntax
program error:  code follows on the same line as close brace
program error:  code follows on the same line as close brace
program error:  code follows on the same line as close brace
r(198);

本人对STATA了解甚少,请各位指点应该怎样纠正程序,谢谢!

原程序如下:
* obtain likelihood based CI limits *
***********************************
* initialize -2LL values
global LL = -2*e(ll)
global refLL = -2*e(ll)
* get interaction coefficient and standard error
matrix A = e(b)
global b3 = A[1,4]
matrix B = e(V)
global seb3 = sqrt(B[4,4])
* initialize other variables
global null = 0
global neglogl = 0
global diff = 0
global param = 0
global step = 0
global lcl = .
global ucl = .
* i = 1 for lower bound and i = 2 for upper bound
forvalues i = 1(1)2 {
         global conv = 0
         global step = $seb3
         global beta = $b3
         global num = 0

    while $conv == 0       {
         global num = $num + 1
    constraint define $num _b[eq2:inter]== $beta
         ml model lf linearodds (cons: ) (case = alcohol smoke inter, nocons),
constraint($num)
         ml init A, copy
         quietly ml maximize, difficult repeat(10)
         global LL = -2*e(ll)
         global diff = ($LL - $refLL)
         if ($diff >= 3.8413 & $diff = 3.8415)  {
                                   if (`i' == 1)    {
                                   global beta = ($beta + $step)
                                                             }
                                   if (`i' == 2)    {
                                   global beta = ($beta - $step)
                                                             }
                                   global step = ($step * 0.5)
                                                }
    disp $num, "null =", %8.4f $refLL," ","neglogl =", %8.4f $LL," ", "diff =", /*
    */   %6.4f $diff," ","step =", %6.4f $step," ","b3 =", %6.4f $beta
                                   if (`i' == 1)    {
                                   global beta = ($beta - $step)
                                                             }
                                   if (`i' == 2)    {
                                   global beta = ($beta + $step)
                                                             }
                                      } /* close of while loop */
} /* close forvalues loop */
disp "-------------------------------------------------------------------------------"
disp "The likelihood based 95% CI limits are:", %6.4f $lcl,",",%6.4f $ucl
有空学习一下!

藤椅
dxystata 发表于 2011-2-12 20:59:41
请和我联系!我可以帮你解决!

板凳
吃葡萄的驴 发表于 2021-6-4 17:50:18
请问你解决了吗?我也出现了这个问题

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-20 01:00