Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Revised - Syntax forvalues in Stata 11 SE -


From   Gauri Khanna <[email protected]>
To   Stata List <[email protected]>
Subject   RE: st: Revised - Syntax forvalues in Stata 11 SE -
Date   Thu, 23 Sep 2010 12:16:54 +0000

Here are the corrected codes - please ignore earlier email:

Gauri 
Thank you for your responses Martin, Neil and Nick.
 
I have defined -local-max1 and here is a more detailed code which shows temporary files as well as draws on other previously saved datasets. I have ended the do file abruptly to try and isolate the syntax problem. 
 
The codes work up to the -forvalues- codes which is the last three lines. 
 
Note that I changed the syntax for the temporary files from ` to ' i.e. `allsvys' to 'allsyvs' which did not run in Stata 11. 
 
Thanks. Gauri 
 
****************************
use  "reshape.dta", clear
gen totalind=0
 
append using "D:\UnitData\0  NCDInfoBase\1.  Analysis Team Only - Harmonization\d. Tobacco Use\Datasets - Results\7 total age grp\total age raw.dta"
replace totalind=1 if totalind==.
replace total_age_group=0 if totalind==1
 
gen sex=0 if sex_code==1
replace sex=1 if sex_code==2
 
gen agegrp=1 if midage<17
replace agegrp=0 if start_age==16 & end_age==16
replace agegrp=0 if agegrp==.
 
*drop untrustworthy WHS, they are BIH, Kazah & Slovakia
*drop if source_code==101692 | source_code==101731 (commented out, reg models already exclude those surveys)
 
*tab un_region if lgsmkd !=. & lgsmkc !=. & sex!=. & total_age_group!=1
*tab un_region
 
gen lgsmkd=.
gen lgsmkc=.
gen lgcigd=.
gen lgcigc=.
gen agesmkd=.
gen agesmkc=.
gen agecigd=.
gen agecigc=.
 
gen smk_d_est=.
gen smk_c_est=.
gen cig_d_est=.
gen cig_c_est=.
 
gen str60 trace21=""
 
gen r2d=.
gen r2c=.
 
gen un_region2=un_region
replace un_region2="Oceania" if un_region =="Melanesia" | un_region=="Polynesia" | un_region=="Micronesia"
replace un_region2="Eastern Europe" if un_name=="Armenia" |  un_name=="Azerbaijan" |  un_name=="Georgia" |  un_name=="Turkey" |  un_name=="Uzbekistan" |  un_name=="Turkmenistan" |  un_name=="Kazakhstan" |  un_name=="Kyrgyzstan" | un_name=="Tajikistan"  
replace un_region2="Southern Europe" if un_name=="Cyprus" | un_name=="Israel" 
 
*save `allsvys1', replace /*OLD CODE: STATA 9*/
save "'allsvys1'", replace
drop if sex_code!=3 & total_age_group!=1 & agegrp==0
save "conversion1.dta", replace
 
****Regression****
 
**for age 16 and more**
 
set more off
set matsize 5000
 
*use `allsvys1', clear /*OLD CODE: STATA 9*/
use "'allsvys1'", clear
egen i=group(un_region2 sex_code) if sex_code!=3 & total_age_group!=1 & agegrp==0
summarize i
local max1=r(max)
gen error1=.
gen error2=.
*save `allsvys', replace /*OLD CODE: STATA 9*/
save "'allsvys'", replace
 
forvalues svy = 1/`max1' { 
    use "'allsvys'", clear
    keep if i==`svy'
}
 
 
Thanks, 
 
Gauri 

----------------------------------------
> From: [email protected]
> To: [email protected]
> Subject: RE: st: AW: Syntax forvalues in Stata 11 SE
> Date: Thu, 23 Sep 2010 12:10:31 +0000
>
> Thank you for your responses Martin, Neil and Nick.
>
> I have defined -local-max1 and here is a more detailed code which shows temporary files as well as draws on other previously saved datasets. I have ended the do file abruptly to try and isolate the syntax problem.
>
> The codes work up to the -forvalues- codes which is the last three lines.
>
> Note that I changed the syntax for the temporary files from ` to ' i.e. `allsvys' to 'allsyvs' which did not run in Stata 11.
>
> Thanks. Gauri
>
> ****************************
> use  "reshape.dta", clear
> gen totalind=0
>
> append using "D:\UnitData\0  NCDInfoBase\1.  Analysis Team Only - Harmonization\d. Tobacco Use\Datasets - Results\7 total age grp\total age raw.dta"
> replace totalind=1 if totalind==.
> replace total_age_group=0 if totalind==1
>
> gen sex=0 if sex_code==1
> replace sex=1 if sex_code==2
>
> gen agegrp=1 if midage<17
> replace agegrp=0 if start_age==16 & end_age==16
> replace agegrp=0 if agegrp==.
>
> *drop untrustworthy WHS, they are BIH, Kazah & Slovakia
> *drop if source_code==101692 | source_code==101731 (commented out, reg models already exclude those surveys)
>
> *tab un_region if lgsmkd !=. & lgsmkc !=. & sex!=. & total_age_group!=1
> *tab un_region
>
> gen lgsmkd=.
> gen lgsmkc=.
> gen lgcigd=.
> gen lgcigc=.
> gen agesmkd=.
> gen agesmkc=.
> gen agecigd=.
> gen agecigc=.
>
> gen smk_d_est=.
> gen smk_c_est=.
> gen cig_d_est=.
> gen cig_c_est=.
>
> gen str60 trace21=""
>
> gen r2d=.
> gen r2c=.
>
> gen un_region2=un_region
> replace un_region2="Oceania" if un_region =="Melanesia" | un_region=="Polynesia" | un_region=="Micronesia"
> replace un_region2="Eastern Europe" if un_name=="Armenia" |  un_name=="Azerbaijan" |  un_name=="Georgia" |  un_name=="Turkey" |  un_name=="Uzbekistan" |  un_name=="Turkmenistan" |  un_name=="Kazakhstan" |  un_name=="Kyrgyzstan" | un_name=="Tajikistan"
> replace un_region2="Southern Europe" if un_name=="Cyprus" | un_name=="Israel"
>
> *save `allsvys1', replace /*OLD CODE: STATA 9*/
> save "'allsvys1'", replace
> drop if sex_code!=3 & total_age_group!=1 & agegrp==0
> save "conversion1.dta", replace
>
> ****Regression****
>
> **for age 16 and more**
>
> set more off
> set matsize 5000
>
> *use `allsvys1', clear /*OLD CODE: STATA 9*/
> use "'allsvys1'", clear
> egen i=group(un_region2 sex_code) if sex_code!=3 & total_age_group!=1 & agegrp==0
> summarize i
> local max1=r(max)
> gen error1=.
> gen error2=.
> *save `allsvys', replace /*OLD CODE: STATA 9*/
> save "'allsvys'", replace
>
> forvalues svy = 1/'max1' {
>     use "`allsvys'", clear
>     keep if i==`svy'
> }
>
>
> Thanks,
>
> Gauri
>
> ----------------------------------------
>> From: [email protected]
>> To: [email protected]
>> Subject: st: AW: Syntax forvalues in Stata 11 SE
>> Date: Thu, 23 Sep 2010 13:55:33 +0200
>>
>>
>> <>
>>
>>
>> How and when is -local- "max1" defined in your code? See this code:
>>
>>
>> *************
>> loc max1 2
>> forv i=1/`max1'{
>> di `i'
>> }
>>
>> loc max1
>> forv i=1/`max1'{
>> di `i'
>> }
>> *************
>>
>>
>>
>> HTH
>> Martin
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [email protected]
>> [mailto:[email protected]] Im Auftrag von Gauri Khanna
>> Gesendet: Donnerstag, 23. September 2010 13:53
>> An: Stata List
>> Betreff: st: Syntax forvalues in Stata 11 SE
>>
>>
>> Hi,
>>
>> I am a new user to the Stata 11.1 SE
>>
>> I have run into syntax problems with the - forvalues- command while creating
>> a loop.
>>
>> My syntax which comes from Stata 9 is the following:
>>
>> forvalues svy = 1/`max1' {
>> use "'allsvys'", clear
>> keep if i==`svy'
>> }
>>
>> and I get the following error :
>>
>> invalid syntax
>> r(198);
>>
>> Subsequently, i would also like to run the following syntax (shortened for
>> convenience)
>>
>> foreach x of local names {
>> if "`x'"=="lgsmkc" {
>> display "`x'"
>> gen row`j'=lgcigc
>> local j=`j'+1
>> }
>> }
>>
>> Can anyone help?
>>
>> Gauri
>>
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>>
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
 		 	   		  
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index