post命令是一個(gè)數(shù)據(jù)整理法寶
These commands are utilities to assist Stata programmers in performing Monte Carlo-type experiments.
The command post and its companion commands postfile and postclose are
described in postfile as “utilities to assist Stata programmers in performing Monte Carlo type experiments”. That description understates their usefulness, as post is one of the most flexible ways to accumulate results and save them for later use in an external file.
There are five commands manipulate the new dataset without disturbing the data in memory.
- postfile declares the variable names and the filename of a (new) Stata dataset where results will be saved.
- post adds a new observation to the declared dataset.
- postclose declares an end to the posting of observations. After postclose, the new dataset contains the posted results and may be loaded using use.
- postutil dir lists all open postfiles.
- postutil clear closes all open postfiles.

假設(shè)你是一名淘寶店主,現(xiàn)在有位顧客購買了手環(huán)、U盤和支架?,F(xiàn)在你需要填份清單隨快遞一并附上。
checklist是空白清單,str30 commodity number price str10 unit是對商品描述的格式規(guī)定,using "C:\Users\Van\Desktop\post命令\checklist.dta"是清單所在的位置
post checklist是顧客購買的商品明細(xì),我們把明細(xì)通過post填寫到清單上
postclose checklist表明清單填寫完畢
postfile checklist str30 commodity number price str10 unit ///
using "C:\Users\Van\Desktop\post命令\checklist.dta", replace
post checklist ("華為榮耀手環(huán)5") (1) (189) ("元")
post checklist ("愛國者U盤32g") (1) (30) ("元")
post checklist ("筆記本支架") (1) (49) ("元")
postclose checklist
use "C:\Users\Van\Desktop\post命令\checklist.dta"
注意post的使用是一組命令,而非一行命令
示例
clear
cd "C:\Users\Van\Desktop\post命令"
postfile hdle foreign rep78 mean using autoinfo.dta, replace
sysuse auto, clear
forvalues f = 0/1 {
forvalues r = 1/5{
summarize price if foreign == `f' & rep78 == `r', meanonly
post hdle (`f') (`r') (r(mean))
}
}
postclose hdle
use autoinfo, clear