Bookmark and Share

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

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

RE: st: use of tempfile

From   "Sarah Edgington" <>
To   <>
Subject   RE: st: use of tempfile
Date   Thu, 19 Apr 2012 11:51:02 -0700

I don't think I have a clearer understanding than anyone else of what exact variables you want in your final data file.  However, that may not matter if your problem really is with making the transition from saved data files to temp files.
My advice is to write the code using standard data files first to get things working.  Make sure you're getting exactly what you want.  
Then change the code to use tempfiles instead of permanent data files.  I think the problem you're having right now is that you're trying to get 1 tempfile to stand in for 20 permanent datasets.  You'll actually need 20 tempfiles.
So every time you -save sales1_1.dta- you could instead say 
tempfile sales1_1
save `sales1_1'
Then when you go to merge you would merge using `sales1_1'
You would then do the same for sales1_2, sales1_3, etc.

If you can't get exactly what you want by writing the code using saved datasets then your problem really is with how to get the underlying structure you're looking for and not with the tempfile syntax.  In that case you'll have to work through that issue first.

Hope that helps.

-----Original Message-----
From: [] On Behalf Of Prakash Singh
Sent: Thursday, April 19, 2012 8:54 AM
Subject: Re: st: use of tempfile

In the "before" data set I have list of variable say "n", now out of these n variables some variable are so kept in the data set that for each state_code they represent sales, export value of certain industry. My interest here to transform the data set in such a way that these sales and export value for the particular industry as separate variables. to put other way around I want to make my data free from state_code.

so if the name of the data file is sales1.dta (before)

Then using keep if command and renaming the numbers in  state_code and other variable I have created data file assigning number identical to the category of state_code. the state_code variable is having 20 different values (category) and that's how I have sales1_1.dta to sales1_20.dta after use of keep if command. Now I have to merge these
20 newly created data set from "before" situation to get one final data set let us call it sales1_1_20.dta "after" situation so that sales, export of different industry will come beside each other as separate variable in one data file. common_id is the variable being able to uniquely identify the observation is sued to merge.

I could write the code but it gives me unnecessary data file which I will not be using in analysis ( all other created data file baring sales1_1_20.dta). One obvious answer is that I can delete them once I have the final data file but then I thought there could some way using that I can bypass save command and that is the reason I have put tempfile as the subject of my query thread.

*   For searches and help try:

*   For searches and help try:

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