我正在使用Stata中的嵌套循环来处理我的第一个循环,但是无法运行代码。
这里是我所拥有的:
render() {
return (
<View style={styles.container}>
<Text style={homeScreenStyles.paddingMedium}>HomeScreen.</Text>
<Navigation navigation={this.props.navigation}/>
</View>
);
}
运行代码时,出现错误:
*identify anti policies of contiguous states
forvalues yr = 1983/1993 {
foreach state in Alabama Alaska Arizona Arkansas California Colorado
Connecticut Delaware Florida Georgia Hawaii
Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland
Massachusetts Michigan Minnesota Mississippi
Missouri Montana Nebraska Nevada NewHampshire NewJersey NewMexico NewYork
NorthCarolina NorthDakota Ohio
Oklahoma Oregon Pennsylvania RhodeIsland SouthCarolina SouthDakota Tennessee
Texas Utah Vermont Virginia
Washington WestVirginia Wisconsin Wyoming {
gen 'st'_anti_'yr'=.
replace 'st'_anti_'yr'=1 if 'st'_c==1 & anti["st"_"yr"]==1
replace 'st'_anti_'yr'=0 if 'st'_c==0 | anti["st"_"yr"]==0
}
}
无论我如何修改代码(添加或删除'或'等),都会显示此错误。
答案 0 :(得分:1)
您需要在每一行的末尾添加///
,以便Stata可以将所有状态视为一条连续的行。将所有状态保存在本地宏中,然后在循环中使用它也是一种好习惯。
例如:
local states Alabama Alaska Arizona Arkansas California Colorado Connecticut ///
Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky ///
Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi ///
Missouri Montana Nebraska Nevada NewHampshire NewJersey NewMexico NewYork ///
NorthCarolina NorthDakota Ohio Oklahoma Oregon Pennsylvania RhodeIsland ///
SouthCarolina SouthDakota Tennessee Texas Utah Vermont Virginia Washington ///
WestVirginia Wisconsin Wyoming
forvalues yr = 1983 / 1993 {
foreach state of local states {
display "`yr' `state'"
}
}
此外,在您的示例中,您似乎错误地指定了本地宏state
,却忘记了对本地宏yr
使用引号:
forvalues yr = 1983 / 1993 {
foreach state of local states {
generate `state'_anti_`yr'=.
replace `state'_anti_`yr'=1 if `state'_c==1 & anti[`state'_`yr']==1
replace `state'_anti_`yr'=0 if `state'_c==0 | anti[`state'_`yr']==0
}
}