On Jan 6, 2008 4:40 PM, Beth Gifford <[email protected]> wrote:
> Hello all
>
> I have a data base with many tables (they represent students within
> schools and then provide additional details on students).
> What I want to do is to have a program for each table ( that labels &
> recodes variables, etc) and that then creates a tempfile with a
> dataset that I can use to do the merging. I'm very close but the
> tempfile gets overwritten when the next program runs. Here is a
> simplified example. The problem is that the school temporary file is
> overwritten by the student temporary file. any suggestions?
>
> ************************
>
> program define p_school, rclass
> clear
> odbc load, dsn("MS Access Database; DBQ=$dbname")
> table("tblSchool") lowercase
> compress
> label define l_lea 1 "Alamance" 2 "Anson" 3 "Bertie" 4
> label val leaid l_lea
> save `0'
> end
>
> program define p_student
> clear
> odbc load, dsn("MS Access Database; DBQ=$dbname")
> table("tblStudent") lowercase
> label define l_gender 1 Missing 2 Male 3 Female
> label val gender l_gender
> save `0'
> end
>
> tempfile d_school
> p_school `d_school'
>
> tempfile d_student
> p_student `d_student'
What Beth got as result is legitimate. It is not that the school
tempfile is overwritten by the student tempfile, but the school
tempfile vanishes itself. To be plain, tempfiles cannot be created
within a program for later use by another program. Anything that is
Temp disappears once the program execution is complete. They are
available for use only within the program that creates them (correct
me anyone if I am wrong); meaning once created, if they are not used,
they will be gone. If Beth is not ready to use the tempfiles within
the programs creating them, then permanent files should be created.
Beth might want to combine the two programs as suggested here (but I
am not sure if it will work, 'cause I've never used the odbc command
before):
***Begin***
capture program drop school_student
program define school_student
clear
odbc load, dsn("MS Access Database; DBQ=$dbname")
table("tblSchool") lowercase
compress
label define l_lea 1 "Alamance" 2 "Anson" 3 "Bertie" 4
label val leaid l_lea
sort varname // for merging purposes
save `0'
clear
odbc load, dsn("MS Access Database; DBQ=$dbname")
table("tblStudent") lowercase
label define l_gender 1 Missing 2 Male 3 Female
label val gender l_gender
sort varname // for merging purposes
save `1'
........... // more code here to use the created tempfiles,
otherwise save files as permanent.
end
tempfile d_school d_student
school_student `d_school' `d_student'
**End**
--
P. Wilner Jeanty, Post-doctoral researcher
Dept. of Agricultural, Environmental, and Development Economics
The Ohio State University
2120 Fyffe Road
Columbus, Ohio 43210
(614) 292-6382 (Office)
*
* 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/