Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: string variables and postfile - elementary question


From   Lee Sieswerda <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: string variables and postfile - elementary question
Date   Thu, 5 Dec 2002 18:32:36 -0500

Switching from -postfile- to the new(-ish) -file- command will allow you to
write non-numeric results. -file- is not in the manuals; you have to type:
help file
I've converted old programs from -postfile- to -file- and it is quite easy.
Best,
Lee

Lee Sieswerda, Epidemiologist
Thunder Bay District Health Unit
999 Balmoral Street
Thunder Bay, Ontario
Canada  P7B 6E7
Tel: +1 (807) 625-5957
Fax: +1 (807) 623-2369
[email protected]
www.tbdhu.com


> -----Original Message-----
> From:	Natalie Karavarsamis [SMTP:[email protected]]
> Sent:	Thursday, December 05, 2002 6:25 PM
> To:	'[email protected]'
> Subject:	st: string variables and postfile - elementary question
> 
> 
> Hello,
> 
> I am using -postfile- within a program to save -rclass- results.
> Initially,
> I have a data set with 30 variables executing commands and then -post-ing
> and saving the results in "`results.dta'". So I end up with `results'.dta
> file with 30 rows (1 record per original variable) and the results stored
> as
> variables (columns). 
> My problem: 1) I want to create a variable (1 column) in the new file
> containing the 30 variable names (30 rows) from the initial file and 2)
> post
> this into the results.dta file. However, postfile will not let me -post-
> non-numeric values i.e strings (i've got the variable names in a local
> macro
> `list'), how do I get around this?
> 
> 
> (I hope I am understandable)
> 
> What I wish I could do was:
> 
> prog define icc	
>   postfile `icchold' nutrient rho lb ub rel N rho_enadj lb_enadj ub_enadj
> rel_enadj N_enadj using "`results'",replace
> 
>   ......code....
> 
>  post `icchold' (return(nut_tmp)) (return(rho_tmp)) (return(lb_tmp))
> (return(ub_tmp)) (return(rel_tmp)) (return(N_tmp)) (return(rhores_tmp))
> (return(lbres_tmp)) (return(ubres_tmp)) (return(relres_tmp))
> (return(Nres_tmp))
> 
> postclose `icchold'
> end
> 
> where nutrient & (return(nut_tmp)) are of string type and all else are
> numeric
> 
> From the program below I want the elements of `varlist' to become the
> values
> of a new variable to be found in 'icc_cmn.dta'.
> I see the solution needing at least two stages; 1) create a new variable
> from the variable names in `varlist' (or `list') and 2) copy this variable
> to the results.dta file.
> 
> 
> This is my whole program:
>  
> cap prog drop icc
> program define icc, rclass
> syntax varlist, results(str)
> tempname icchold 
> 
> local list "`varlist'"
> 
> postfile `icchold' rho lb ub rel N rho_enadj lb_enadj ub_enadj rel_enadj
> N_enadj using "`results'",replace
> quietly {
> 	foreach i of varlist `varlist' {
> 		return local nut_tmp "`i'"		
> 		loneway `i' studyid 
> 		return scalar rho_tmp = r(rho)
>  		return scalar lb_tmp = r(lb)
> 		return scalar ub_tmp = r(ub)
> 		return scalar rel_tmp = r(rho_t)
> 		return scalar N_tmp = r(N)
> 		enadjust `i' kilojoules
> 		loneway `i'res studyid
> 		return scalar rhores_tmp = r(rho)
>  		return scalar lbres_tmp = r(lb)
> 		return scalar ubres_tmp = r(ub)
> 		return scalar relres_tmp = r(rho_t)
> 		return scalar Nres_tmp = r(N)
> 		post `icchold' (return(rho_tmp)) (return(lb_tmp))
> (return(ub_tmp)) (return(rel_tmp)) (return(N_tmp)) (return(rhores_tmp))
> (return(lbres_tmp)) (return(ubres_tmp)) (return(relres_tmp))
> (return(Nres_tmp))
> 	}
> }
> postclose `icchold' 
> end
> 
> use studyid time water-folate using reshaped,clear
> 
> icc water-folate, results(icc_cmn) 
> 
> Thanks
> Natalie
> 
> --------------------------------------------
> Natalie Karavarsamis
> 
> Statistician
> Cancer Epidemiology Centre
> The Cancer Council Victoria
> 1 Rathdowne Street
> Carlton VIC 3053
>  
> ph: (03) 9635 5159
> fax: (03) 9635 5330
> www.cancervic.org.au
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index