seb obs 30
gen t=_n+1
tsset t,d
gen tx=_n+1+t
tsset tx,d
gen gap=tx-t
format %9.0g t
format %9.0g tx
gen gapn = tx-t
Posts Tagged ‘Stata’
stata time gap
Posted by changjx on October 30, 2009
Posted in Uncategorized | Tagged: Stata | Leave a Comment »
extract coef,se,t,pv from stata reg
Posted by changjx on May 26, 2009
Maarten Buis’s method to extract estimate from stata reg
——-begin correct code —
sysuse auto, clear
reg price mpg rep78 headroom trunk weight
matrix a = vecdiag(e(V))
matrix b = (e(b)\a)’
svmat b
rename b1 beta
gen se = sqrt(b2)
gen t = beta/se
gen p = 2*ttail(63,abs(t))
——— end correct code—–
Or use May’s code
Read the rest of this entry »
Posted in Stata, Uncategorized | Tagged: econometrics, Stata | Leave a Comment »
data management in household data
Posted by changjx on June 27, 2008
#stata
cd “c:\data\”
reserve
keep id itm* amt*
outsheet using “c:\data\inc95t.txt”,comma
restore
Read the rest of this entry »
Posted in EconStatistics, Stata | Tagged: SAS, Stata | Leave a Comment »
probit ml in stata and R
Posted by changjx on June 24, 2008
/* Stata */
clear
set obs 1000
gen x=invnorm(uniform())
gen e=invnorm(uniform())
gen y=0.5+0.4*x+e
replace y=0 if y<=0
replace y=1 if y>0
Read the rest of this entry »
Posted in EconStatistics, R, Stata | Tagged: R, Stata | Leave a Comment »
hausman test
Posted by changjx on June 18, 2008
xtreg $output $input,fe
estimates store fixed
xtreg $output $input,re
hausman fixed .
Posted in Econ, Stata | Tagged: econometrics, Stata | Leave a Comment »
gen non constant error in regression
Posted by changjx on June 10, 2008
set obs 1000
sca a=2
sca b=2
sca wt=10
gen x=uniform()*100
gen e=invnorm(uniform())
gen y=a+b*x+wt*e
reg y x
Posted in Stata | Tagged: Stata | Leave a Comment »
mata poisson
Posted by changjx on April 27, 2008
From Colin Cameron
http://cameron.econ.ucdavis.edu/stata/stata.html
* This program does
Posted in R, Stata | Tagged: R, Stata | Leave a Comment »
optimize in R et stata
Posted by changjx on April 13, 2008
stata
version 10
mata
void myeval(todo, x, y, g, H){
y = exp(-x^2 + x – 3)
}
S = optimize_init()
optimize_init_evaluator(S, &myeval())
optimize_init_params(S, 0)
x = optimize(S)
x
end
R
fr<-function(x){
-exp(-x^2+x-3)}
optim(c(0),fr,method=”BFGS”)
Posted in R, Stata | Tagged: R, Stata | Leave a Comment »
different y axis unit
Posted by changjx on March 6, 2008
Stata
twoway connected y t ||connected var2 t, yaxis(2)
R
par(mar=c(5,4,2,4),bg=’snow2′)
plot(unemp~tse,type=’b',pch=16,
col=4,ylab=”,xaxt=’n',xlab=’Time’)
#minor axis
axis(1,at=stse,labels=stse,
col.axis=1, las=1,tck=-0.009)
#major axis
axis(1,at=ltse,labels=ltse,tck=0.009)
abline(v=1958,col=’purple’,lwd=2)
mtext(‘Unemployment rate’,2,padj=-3.5)
#y2 axis
par(new=T)
plot(GNP~tse,xaxt=’n',ann=F,yaxt=’n',col=2,
xlab=”,ylab=’GNP’,type=’b',pch=15)
axis(4,at=seq(80,120,7),
labels=seq(80,120,7))
mtext(‘GNP’,4,padj=3.5)
/*SAS*/
%LET PATH=C:\DATA;
DATA LONG;
INFILE “&PATH\LONGLY.CSV” DLM=’,';
INPUT GNPD GNP Unemp ArmedF Population Year Employed;
RUN;
goptions reset=all cback=WHITE;
/*V=DOT,STAR,CIRCLE,SQUARE*/
SYMBOL1 C=BLUE V=DOT L=1 W=1 I=JOIN;
SYMBOL2 C=RED V=STAR L=2 W=1 I=JOIN;
/* Create axis definitions F:TIME FORMAT(‘Helvetica’),
H:HEIGHT*/
AXIS1 LABEL=(F=times H=4 PCT
ANGLE=90 ‘GNP’) OFFSET=(0,0) ORDER=(200 TO 600 BY 50);
AXIS2 LABEL=(F=times H=4 PCT ANGLE=90 ‘UNEMP’)
OFFSET=(0,0) ORDER=(100 TO 500 BY 50);
AXIS3 ORDER=(1947 TO 1962 BY 2);
/*cREATE LEGEND CONTENT*/
LEGEND1 LABEL=none VALUE=(‘GNP’ ‘unemp’)
position=(top left inside)offset=(3,-1);
LEGEND2 LABEL=none VALUE=(‘UNEMP’)
position=(top left inside) offset=(3,-2.5);
TITLE F=times H=4 PCT ‘SAS GPLOT’;
PROC GPLOT DATA=LONG;
PLOT GNP*YEAR/OVERLAY VAXIS=AXIS1 HAXIS=AXIS3 LEGEND=LEGEND1 HREF = 1958;
PLOT2 UNEMP*YEAR/OVERLAY VAXIS=AXIS2 LEGEND=legend2;
RUN;
QUIT;
Posted in R, SAS, Stata | Tagged: Graphics, R, SAS, Stata | Leave a Comment »