post命令是一个数据整理法宝
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.
假设你是一名淘宝店主,现在有位顾客购买了手环、U盘和支架。现在你需要填份清单随快递一并附上。
checklist
是空白清单,str30 commodity number price str10 unit
是对商品描述的格式规定,using "C:\Users\Van\Desktop\post命令\checklist.dta"
是清单所在的位置
post checklist
是顾客购买的商品明细,我们把明细通过post填写到清单上
postclose checklist
表明清单填写完毕
postfile checklist str30 commodity number price str10 unit ///
using "C:\Users\Van\Desktop\post命令\checklist.dta", replace
post checklist ("华为荣耀手环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