Stata:使用forvalue循环标记变量
我试图使用循环标记一批变量,如下所示,但由于stata错误“无效语法”而失败。我找不出哪里出了问题Stata:使用forvalue循环标记变量,stata,Stata,我试图使用循环标记一批变量,如下所示,但由于stata错误“无效语法”而失败。我找不出哪里出了问题 local myvars "basicenumerator" "basicfr_gpslatitude" "basicfr_gpslongitude" local mylabels "Name of enumerator" "the latitude of the farmers house" "the longtitude of the farmers house" local n :
local myvars "basicenumerator" "basicfr_gpslatitude" "basicfr_gpslongitude"
local mylabels "Name of enumerator" "the latitude of the farmers house" "the longtitude of the farmers house"
local n : word count `mylabels'
forvalues i = 1/`n'{
local a: word `i' of `mylabels'
local b: word `i' of `myvars'
label var `b' "`a'"
}
要调试它,主要的技巧是让Stata向您展示它认为本地宏是什么。此脚本使您的代码具有可复制性,并对其进行了修复
clear
set obs 1
gen basicenumerator = 42
gen basicfr_gpslatitude = 42
gen basicfr_gpslongitude = 42
local myvars `" "basicenumerator" "basicfr_gpslatitude" "basicfr_gpslongitude" "'
local mylabels `" "Name of enumerator" "the latitude of the farmers house" "the longtitude of the farmers house" "'
local n : word count `mylabels'
mac li
forvalues i = 1/`n'{
local a: word `i' of `mylabels'
local b: word `i' of `myvars'
label var `b' "`a'"
}
问题是,在定义局部变量时,外部的“
会被剥离,因此要使”
符合需要,需要将每个字符串用双引号括起来
有关说明,请参见12.4.6
挑剔的纠正:拼写是经度 要调试它,主要的技巧是让Stata向您展示它认为本地宏是什么。此脚本使您的代码具有可复制性,并对其进行了修复
clear
set obs 1
gen basicenumerator = 42
gen basicfr_gpslatitude = 42
gen basicfr_gpslongitude = 42
local myvars `" "basicenumerator" "basicfr_gpslatitude" "basicfr_gpslongitude" "'
local mylabels `" "Name of enumerator" "the latitude of the farmers house" "the longtitude of the farmers house" "'
local n : word count `mylabels'
mac li
forvalues i = 1/`n'{
local a: word `i' of `mylabels'
local b: word `i' of `myvars'
label var `b' "`a'"
}
问题是,在定义局部变量时,外部的“
会被剥离,因此要使”
符合需要,需要将每个字符串用双引号括起来
有关说明,请参见12.4.6
挑剔的纠正:拼写是经度