- Stata Blog: Programming an estimation command in Stata: A map to posted entries
- Manage the ado programs
- Stata Syntax-highlighting for Notepad++ or download from the Notepad++ website
- Syntax Highlight Packages (Dynamic documents in Stata: MarkDoc, Ketchup, and Weaver): Synlight, Weaver, MarkDoc
- Determine build-in command or ado-file: which command
- Check codes: viewsource command or type "directory\xxx.ado"
- list of the packages: ado dir
- Install: ssc install package
- check update: adooupdate
- update: adoupdate, update
- uninstall: ado uninstall package|[#]
- re-run profile.do: do profile.do
- How to edit an ado file, '- ADOEDIT -': module to edit ado file in Stata's do-file editor
- Programming Stata of Stata Tutorial - Princeton University.
- The University of Wisconsin provides nice websites for Stata for Researchers and Programming in Stata. The new Stata Programming Essentials is better for new programmers and the new Stata Programming Tools is better for more advanced persons.
- Macro: global and local macros: macro dir/macro drop
- Example Macro with `' and/or "":
- for both local and global macro, braces { and } can be used to form nested constructions.
- global pth "c:\abc\"
- di "${pth}def\" // ==> c:\abc\def\
- local x 2+2
- di "x" // ==> x
- di `x' // ==> 2+2 ==> 4
- di "`x'" // ==> 2+2
- local x=2+2 // ==> local x 4
- di `x' // ==> 4
- di "`x'" // ==> 4
- di "`=2+2'" // ==> 4
- di "`2+2'" // ==> N/A
- local x 2
- di "`=`x'-2'" // ==> 0
- local pth "c:\project"
- di "`pth'\data\" //==> "c:\project\data\"
- global pt "c:\project"
- di "$pt\data\" //==> "c:\project\data\"
- di "${pt}data\" //==> "c:\projectdata\"
- local a 2+3
- local b 7
- display `a'+`b' //==> 10
- display "`a'+`b'" //==> 2+3+7
- display "`a'"+"`b'" //==> 2+3+"7" invalid name
- display "`a'""+""`b'" //==> 2+3+7
- regress mpg weight
- local rsqf e(r2)
- local rsqv = e(r2)
- di "R-squared_1f=`rsqf'" //==> R-squared_1f=e(r2)
- di "R-squared_1v=`rsqv'" //==> R-squared_1v=.6515312529087511
- di "R-squared_2f=" `rsqf' //==> R-squared_2f=.65153125
- di "R-squared_2v=" `rsqv' //==> R-squared_2v=.65153125
- di "R-squared_3f=" "``rsqf''" //==> R-squared_3f=.6515312529087511
- di "R-squared_3v=" "``rsqv''" //==> N/A
- Stata Blog: Programming an estimation command in Stata
- Example 1: Storing and extracting the result of an extended macro function
- local count : word count a b c
- display "count contains `count'" ==> count contains 3
- Example 2: Using gettoken to store first token only
- local mylist y x1 x2
- display "mylist contains `mylist'" ==> mylist contains y x1 x2
- gettoken first : mylist
- display "first contains `first'" ==> first contains y
- Example 3: Using gettoken to store first and remaining tokens
- gettoken first left: mylist
- display "first contains `first'" ==> first contains y
- display "left contains `left'" ==> left contains x1 x2
- Example 4: Local macro update
- local p = 1
- local p = `p' + 3
- display "p is now `p'" ==> p is now 4
- Example 5: Local macro update
- local p = 1
- local ++p
- display "p is now `p'" ==> p is now 2
Disclaimer: This blog site is intended solely for sharing of information. Comments are warmly welcome, but I make no warranties regarding the quality, content, completeness, suitability, adequacy, sequence, or accuracy of the information.
Monday, November 19, 2012
Stata Programming
Stata programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment