Hello everybody,
I am currently working on the calculation of an agricultural index. In order to do that, the necessary do-files and datasets (to first try it out) were online available. Since I am completely new to Stata I quickly run into problems.
My question at the moment, is that while I am running the data preparation do file I always receive the error 'variable ... already defined' during similar lines of coding.
(*OWNERSHIP: Adequate if selfjoint owns AT LEAST two small assets (chicken, farming equipment non-mechanized, and small consumer durables) OR one large asset (all the other).
* This is the same to say: empowered if owns AT LEAST one assets and that asset is not a small asset.
* Inadequate if lives in a household that owns no assets) - Description of what is beng down
foreach x in own{
egen selfjoint`x'sum=rowtotal(selfjoint`x'_*), missing
egen j`x'count=rowmax(selfjoint`x'_*)
replace j`x'count=0 if j`x'count==1 & selfjoint`x'sum==1 &(selfjointown_d==1|selfjointown_f==1|selfjointown _k==1)
replace j`x'count=0 if own_sum==0
rename j`x'count j`x'_count
rename selfjoint`x'sum selfjoint`x'_sum
}
Oftentimes when I run a "foreach x in own" line of code I receive the same type of error ('variable ... already defined')


I was looking into the different variables where this happened with the describe function and this is what I found (whereas, I am also not sure what this is telling me)
describe selfjointownsum
Variable Storage Display Value
name type format label Variable labe
> l
-----------------------------------------------------------
selfjointownsum float %9.0g
Does anybody understand the problem or knows how it can be solved?
Thank you very much
Franziska
I am currently working on the calculation of an agricultural index. In order to do that, the necessary do-files and datasets (to first try it out) were online available. Since I am completely new to Stata I quickly run into problems.
My question at the moment, is that while I am running the data preparation do file I always receive the error 'variable ... already defined' during similar lines of coding.
(*OWNERSHIP: Adequate if selfjoint owns AT LEAST two small assets (chicken, farming equipment non-mechanized, and small consumer durables) OR one large asset (all the other).
* This is the same to say: empowered if owns AT LEAST one assets and that asset is not a small asset.
* Inadequate if lives in a household that owns no assets) - Description of what is beng down
foreach x in own{
egen selfjoint`x'sum=rowtotal(selfjoint`x'_*), missing
egen j`x'count=rowmax(selfjoint`x'_*)
replace j`x'count=0 if j`x'count==1 & selfjoint`x'sum==1 &(selfjointown_d==1|selfjointown_f==1|selfjointown _k==1)
replace j`x'count=0 if own_sum==0
rename j`x'count j`x'_count
rename selfjoint`x'sum selfjoint`x'_sum
}
Oftentimes when I run a "foreach x in own" line of code I receive the same type of error ('variable ... already defined')
I was looking into the different variables where this happened with the describe function and this is what I found (whereas, I am also not sure what this is telling me)
describe selfjointownsum
Variable Storage Display Value
name type format label Variable labe
> l
-----------------------------------------------------------
selfjointownsum float %9.0g
Does anybody understand the problem or knows how it can be solved?
Thank you very much

Franziska

Comment