|
ProductsPricesAustraliaNew ZealandSupportOrder form Quotation request Contact us |
Stata is a general-purpose statistical package for researchers of all disciplines. Epidemiology
Longitudinal/Panel Data
Multivariate Methods
Survey Data
Survival Analysis
Time-Series
Multiple Imputation
Structural Equation Modelling
![]() and Statistics useful across other fields In addition, Stata produces publication-quality graphics, contains extensive
data-management capabilities, and has a powerful matrix-programming language.
What's New in Stata 12?
Go here for a comprehensive
overview of what's new in Stata 12.
Stata Tip Using Stata's file command one:two:three:four one1:two1 For this example assume that we require only the last 2 words in a new file (the words are delimited with a ":") An example of a Stata program that will create a new file with only the last 2 words of each line is:
program ltype //(1)
version 12.1
syntax , Current(string) New(string) P(string) //(2)
tempname fh hdl //(3)
file open `fh' using `"`current'"', read //(4)
file open `hdl' using `"`new'"', replace write text //(5)
file read `fh' line //(6)
while r(eof)==0 { //(7)
local kk=reverse("`line'") //(8)
tokenize `kk',p("`p'") //(9)
local No1 "`=reverse("`1'")'" //(10)
local No3 "`=reverse("`3'")'" //(10)
file write `hdl' %st10 ("`No1'") %st10 (":") %st10 ("`No3'") _newline //(11)
file read `fh' line //(12)
}
file close _all //(13)
end
Going through the above:(1) program The start of the program starts with program and a name of the program: ltype. The program finishes with end. (2) syntax command, passes information to the program via local macros ie. current is the macro name containing the file name of the initial file (raw data). new is the name of the local macro that contains the file name for the information obtained by the program (last 2 words of line). p is the local macro name of the delimiter. (3) Creating tempory names (4) Opening the file with the initial information (5) Opening a file for the required data to be entered (6) Read the first line of the file and store this in the local macro line (7) While loop; continues until end of file is reached (8) Reverse the order of the contents of the line macro so the last word becomes the first (9) tokenize the line based on the parse character : ; break string into local macro's with names: 1,2 etc. (10) make the contents of the local macro's No1 and No3 the reverse of the last and 2nd last words (: is treated as a word) (11) writes macro contents to the new file separating then with ":" (12) read new line of file (13) closes both files Then the above program can be run with the following:
type "c:/file_try.txt"
ltype ,current("c:/file_try.txt") new( "c:/file_try1.txt") p(":")
type "c:/file_try1.txt"
infile str10 a using "c:/file_try1.txt", clear //loading file into Stata
list
For help on specific commands type: help and then the specific command eg. help program help file help tempname help while help reverse() help tokenize help local help type Contact
details If our office is not attended, please leave your message as well as your phone number or Email address on our answering machine. You can send an Email or fax at any time and we will attend to it as soon as we can. ********************************************************************************************* Our company is:
******************************************************************************************** 'Stata is a registered trademark of StataCorp LP, College Station, TX, USA, and the Stata logo is used with the permission of StataCorp.'
|