Dear Statalist community,
I am using a loop with while in Stata 13.0 on Windows 10. I have the following code that I am running:
After executing, Stata is showing me the error (198): 'a' invalid name. When I try to trace the error it seems that Stata does not recognize 'a' the second time it runs the loop.
I have tried to change '' into ‘’, I've run my entire code (and not only the loop), but nothing seems to solve the issue.
Some more information: I use an ordered logit model and the dataset contains 23 variables. I use the loop to make a plot that shows the interaction between treatiesmem_open_a and gmi_a (following Matt Golder's example from http://mattgolder.com/files/interact...teraction3.pdf). The variable of interest ranges from 0-810 (that why I use the command while.) After scalar the mean of each variable is given.
Thank you in advance. I am happy to provide more information.
Jaantje
I am using a loop with while in Stata 13.0 on Windows 10. I have the following code that I am running:
Code:
preserve
set seed 339487731
drawnorm SN_b1-SN_b26, n(1000000) means(e(b)) cov(e(V)) clear
postutil clear
postfile mypost prob_hat0 lo0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi using "C:\Users\Anja\Documents\Esmées werk\Datasets\interaction_dataset2_test.dta", replace
noisily display "start"
local a = 0
while ‘a’ <= 810 {
{
scalar h_treatiesmem_open_a=5.686188
scalar h_gmi_a=238.3265
scalar h_treatiesmem_open_b=5.736796
scalar h_gmi_b=231.458
scalar h_interaction_b=6544.354
scalar h_contig=.3270718
scalar h_comlang_ethno=.3071823
scalar h_colony=.0729282
scalar h_lndistcap=7.607629
scalar h_lngdp1_a=8.343579
scalar h_lngdp1_b=8.350814
scalar h_lnpop_a=16.56221
scalar h_lnpop_b=16.48816
scalar h_Landlocked_a=.1403315
scalar h_Landlocked_b=.1546961
scalar h_Agri_gdp_a=15.7774
scalar h_Agri_gdp_b=17.01067
scalar h_com_law_a=.2981366
scalar h_com_law_b=.3240506
scalar h_polity2_a=-.1072913
scalar h_polity2_b=.2903407
scalar h_constant=1
generate x_betahat0 = SN_b1*h_treatiesmem_open_a ///
+ SN_b2*‘a’ ///
+ SN_b3*h_treatiesmem_open_a*‘a’ ///
+ SN_b4*h_treatiesmem_open_b ///
+ SN_b5*h_gmi_b ///
+ SN_b6*h_interaction_b ///
+ SN_b7*h_contig ///
+ SN_b8*h_comlang_ethno ///
+ SN_b9*h_colony ///
+ SN_b10*h_lndistcap ///
+ SN_b11*h_lngdp1_a ///
+ SN_b12*h_lngdp1_b ///
+ SN_b13*h_lnpop_a ///
+ SN_b14*h_lnpop_b ///
+ SN_b15*h_Landlocked_a ///
+ SN_b16*h_Landlocked_b ///
+ SN_b17*h_Agri_gdp_a ///
+ SN_b18*h_Agri_gdp_b ///
+ SN_b19*h_com_law_a ///
+ SN_b20*h_com_law_b ///
+ SN_b21*h_polity2_a ///
+ SN_b22*h_polity2_b ///
+ SN_b23*h_constant
generate x_betahat1 = SN_b1*(h_treatiesmem_open_a+1) ///
+ SN_b2*‘a’ ///
+ SN_b3*(h_treatiesmem_open_a+1)*‘a’ ///
+ SN_b4*h_treatiesmem_open_b ///
+ SN_b5*h_gmi_b ///
+ SN_b6*h_interaction_b ///
+ SN_b7*h_contig ///
+ SN_b8*h_comlang_ethno ///
+ SN_b9*h_colony ///
+ SN_b10*h_lndistcap ///
+ SN_b11*h_lngdp1_a ///
+ SN_b12*h_lngdp1_b ///
+ SN_b13*h_lnpop_a ///
+ SN_b14*h_lnpop_b ///
+ SN_b15*h_Landlocked_a ///
+ SN_b16*h_Landlocked_b ///
+ SN_b17*h_Agri_gdp_a ///
+ SN_b18*h_Agri_gdp_b ///
+ SN_b19*h_com_law_a ///
+ SN_b20*h_com_law_b ///
+ SN_b21*h_polity2_a ///
+ SN_b22*h_polity2_b ///
+ SN_b23*h_constant
gen prob0=logistic(x_betahat0)
gen prob1=logistic(x_betahat1)
gen diff=prob1-prob0
egen probhat0=mean(prob0)
egen probhat1=mean(prob1)
egen diffhat=mean(diff)
tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi
_pctile prob0, p(2.5,97.5)
scalar ‘lo0’ = r(r1)
scalar ‘hi0’ = r(r2)
_pctile prob1, p(2.5,97.5)
scalar ‘lo1’= r(r1)
scalar ‘hi1’= r(r2)
_pctile diff, p(2.5,97.5)
scalar ‘diff_lo’= r(r1)
scalar ‘diff_hi’= r(r2)
scalar ‘prob_hat0’=probhat0
scalar ‘prob_hat1’=probhat1
scalar ‘diff_hat’=diffhat
post mypost (‘prob_hat0’) (‘lo0’) (‘hi0’) (‘prob_hat1’) (‘lo1’) (‘hi1’) ///
(‘diff_hat’) (‘diff_lo’) (‘diff_hi’)
}
drop x_betahat0 x_betahat1 prob0 prob1 diff probhat0 probhat1 diffhat
local a=‘a’+ 1
display "." _c
}
display ""
postclose mypost
restore
merge using "C:\Users\Anja\Documents\Esmées werk\Datasets\interaction_dataset2_test.dta"
After executing, Stata is showing me the error (198): 'a' invalid name. When I try to trace the error it seems that Stata does not recognize 'a' the second time it runs the loop.
I have tried to change '' into ‘’, I've run my entire code (and not only the loop), but nothing seems to solve the issue.
Some more information: I use an ordered logit model and the dataset contains 23 variables. I use the loop to make a plot that shows the interaction between treatiesmem_open_a and gmi_a (following Matt Golder's example from http://mattgolder.com/files/interact...teraction3.pdf). The variable of interest ranges from 0-810 (that why I use the command while.) After scalar the mean of each variable is given.
Thank you in advance. I am happy to provide more information.
Jaantje

Comment