重复贴!有版友反映,我通过论坛电信通道(https://bbs.pinggu.org/thread-325915-1-1.html)上传的该文档部分教育网用户无法下载,特重新上传!
A Must Read for Stata Programming!
论坛上有此文档的word版本,但格式很乱,而且没有相应链接,使用起来很不方便。现忙里偷闲将其处理成pdf版本,创建了全部链接,并重排版面尽可能使其美观,看起来舒服;同时添加了全部数据和程序文档。
低价有偿分享,希望看过用过觉得好的朋友顶一个,让更多人享有好东西。
引用作者的话“The (Stata programming) manual does a good job of detailing what particular commands do; it does not show how the features work together, and that is what I have tried to focus on...I hope I have communicated the grammar of Stata and not just the vocabulary.”
Table of Contents
Lecture 1..........................................................................................................................1
Review of Stata's programming features............................................................................1
Parsing.....................................................................................................................................4
Parsing options........................................................................................................................8
Parsing complicated syntax.................................................................................................11
Aside on subprograms.........................................................................................................16
Lecture 2........................................................................................................................19
Quotes....................................................................................................................................19
Development continues........................................................................................................23
Temporary variables.............................................................................................................25
Development continues........................................................................................................27
An aside concerning r()........................................................................................................30
Development continues........................................................................................................30
Programming the formulas..................................................................................................31
Putting it together..................................................................................................................35
Lecture 3........................................................................................................................41
What you must learn.............................................................................................................41
Scalars...................................................................................................................................42
Binary accuracy.....................................................................................................................44
Accuracy of macros versus scalars....................................................................................46
Converting a program from macros to scalars.................................................................47
Handling by() options............................................................................................................48
Sorting....................................................................................................................................50
Low-level parsing..................................................................................................................51
Programming immediate commands.................................................................................52
Rewriting mytt in terms of mytti...........................................................................................56
Parsing new variables..........................................................................................................58
Lecture 4........................................................................................................................62
Where are we?......................................................................................................................62
Saved results........................................................................................................................63
What can be returned in r()?...............................................................................................66
Referring to returned results in other programs...............................................................67
Referring to returned results in the program that sets them...........................................68
Other types of returned values: s() and e().......................................................................70
s-class returned values........................................................................................................70
e-class returned results........................................................................................................71
Writing post-estimation commands....................................................................................72
Writing an estimation (e class) command.........................................................................74
An alternative estimation-command outline......................................................................77
Writing estimation commands from first principles..........................................................78
Writing estimation commands via maximum likelihood...................................................82
Lecture 5........................................................................................................................85
Restricting commands to the relevant subsample...........................................................85
Which is better: marksample or mark?..............................................................................88
Programming by varlist:........................................................................................................89
Lists........................................................................................................................................91
Creating lists..........................................................................................................................91
Stepping through list elements one-by-one......................................................................94
Deleting elements from lists................................................................................................95
Adding elements to lists.......................................................................................................96
Macro vectors........................................................................................................................96
Parsing revisited: gettoken..................................................................................................99
Quietly blocks.......................................................................................................................100
The relation between capture and quietly.......................................................................104
Capture blocks.....................................................................................................................104
Naming conventions...........................................................................................................107
Program naming convention.............................................................................................110
Calling convention...............................................................................................................110
Version control.....................................................................................................................112
Conclusion...........................................................................................................................113
Exercises & Answers..................................................................................................114
Exercises & Answers in Lecture 1....................................................................................114
Exercises & Answers in Lecture 2....................................................................................117
Exercises & Answers in Lecture 3....................................................................................129
Exercises & Answers in Lecture 4....................................................................................144
Exercises & Answers in Lecture 5....................................................................................154
[此贴子已经被作者于2008-6-24 19:22:16编辑过]