简单模型,我看过matlab code
如果你熟悉matlab,我可上传.
model:Y=alpha+beta*X+eta
moment conditions:[E(eta);E(X*eta)]=0
原始文件来自:
http://www.mathworks.com/matlabcentral/fileexchange/12114-gmm
为方便在matlab & R比较,我把数据截出.
gmmestimation.m
gmmweightmatrix.m
linearmodel01.m
gmm.xls
gmm.csv
number=100;
para0=[0;1];
[paraest,t_sta,V]=gmmestimation('linearmodel01',para0,Y,X,Z,number,2)
%paraest =
% 1.0144
% 1.9802
%t_sta =
% 87.3992
% 178.1722
%V =
% 1.0e-003 *
% 0.1347 0.0092
% 0.0092 0.1235
%%%%%%in R command window
library(gmm)
data=read.csv("gmm.csv")
y=data[,1]
z=data[,2]
iv=data[,3]
res=gmm(z~y,x=iv,type ="cue",vcov = "HAC")
summary(res)
Call:
gmm(g = z ~ y, x = iv, type = "cue", vcov = "HAC")
Method: cue
Kernel: Quadratic Spectral
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.014328 0.011195 90.605819 0.000000
y 1.980223 0.011052 179.166619 0.000000
J-Test: degrees of freedom is 0
J-test P-value
Test E(g)=0: 7.80437246654343e-30 *******
#############
#####in TSP
知道zhangtao兄对TSP也很有兴趣
也一并提供simplegmm.tsp的执行结果
simplegmm.tsp
PROGRAM
COMMAND ***************************************************************
1 options memory=4;
2 FREQ N;
3 SMPL 1 1000;
4 READ(file='GMM.XLS');
5 frml eq1 y = alpha + beta*x;
6 param alpha beta;
7 GMM (INST=(C,Z)) EQ1 ;
8
8 END;
EXECUTION
*******************************************************************************Current sample: 1 to 1000 GENERALIZED METHOD OF MOMENTS
=============================
WITH STARTING VALUES VIA:
NONLINEAR TWO STAGE LEAST SQUARESEQUATIONS: EQ1INSTRUMENTS: C Z
.....
.....
Number of observations = 1000 E'PZ*E = .175761E-30 Standard
Parameter Estimate Error t-statistic P-value
ALPHA 1.01433 .010882 93.2138 [.000]
BETA 1.98022 .011003 179.967 [.000]
epoh 发表于 2011-10-28 21:28
原始文件来自: http://www.mathworks.com/matlabcentral/fileexchange/12114-gmm为方便在matlab & R比较 ...
先回答6楼的问题
举个matlab简单的例子:
fminsearch
Find minimum of unconstrained multivariable function
using derivative-free method Equation
Syntax
x = fminsearch(fun,x0)
%%%%%%example
banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2;
[x,fval,exitflag] = fminsearch(banana,[-1.2, 1])
x =
1.0000 1.0000
fval =
8.1777e-010
exitflag =
1
%%%%%%%%%%%
另在这个帖子
https://bbs.pinggu.org/forum.php?mod=viewthread&tid=1203180&pid=10501719&page=2&extra=#pid10501719
我是用fmincon求解lstar系数
[para]=fmincon(@(para)lstarSSE(para,y,X,q),init,[],[],[],[],lb,ub)
回覆 7,8楼 gauss code
由于是手动逐一输入参数,
比较繁复,我就点到为止.
*********************************************************************
Select 1 for fixed weights
Select 2 for time-varying weights
Note: Select 1 to replicate the results in DdPS(2007) and DHPS(2007).
Some results in DdPS(2007) are also provided for option 2.
**********************************************************************
? 1
****************************************************************************************
The fixed weights are calculated based on the average of 3 (consecutive) years.
Enter the starting year.
Notes:
(i) Enter the year 1999 to replicate the results in both DdPS(2007) and DHPS(2007)
(ii) The latest starting year that can be selected for this dataset is: 2007
****************************************************************************************
? 1999
**********************************************************************************
Select 0, for exact-identifying restrictions on the long run parameters when
performing cointegration analysis of the VARX* models
Select 1, for over-identifying restrictions using the exchange rate expressed
viz a viz the US dollar
Select 2, for over-identifying restrictions using the effective exchange rate
Notes:
(i) Select 0, to replicate the results in DdPS(2007)
(ii) Select 2, to replicate the results in Table 5 in DHPS(2007)
(iii) Options 1 and 2 should be used with the fixed weights option. Over-identifying
restrictions are placed on 11 out of the 26 country/regions
***********************************************************************************
? 0
****************************************
Individual country VARX order selection
****************************************
Select 1 for AIC
Select 2 for SBC
Note: Select 1 to replicate the results in DdPS(2007) and DHPS(2007)
? 1
***************************************************************************************
Select one of the following where p,q are the lags lengths of the domestic (endogenous)
and foreign (star) variables respectively:
1 for p=q
2 for p<=q
3 for p>q and q/=kmax
4 for no restriction on p,q
Note: Select 3 to replicate the results in both DdPS(2007) and DHPS(2007)
kmax denotes the maximum order of the GVAR
****************************************************************************************
? 3
******************************************************************************
Individual country VARX order for domestic & star variables based on AIC
p: var order of domestic variables
q: var order of star variables
******************************************************************************
Country p q
China 1 1
EuroArea 2 1
Japan 2 1
Argentina 2 1
Brazil 2 1
Chile 2 1
Mexico 1 1
Peru 2 1
Australia 1 1
Canada 2 1
NewZealand 2 1
Indonesia 2 1
Korea 2 1
Malaysia 1 1
Philippines 2 1
Singapore 2 1
Thailand 2 1
India 2 1
SAfrica 2 1
SaudiArabia 2 1
Turkey 2 1
Norway 2 1
Sweden 2 1
Switzerland 2 1
UK 1 1
US 2 1
*********************************************************************************
Select 1: To keep the var order specification for the endogenous variables
the same as that given above
Select 2: To change the var order specification for the endogenous variables
for a subset or all countries
Select 3: To set the var order of the endogenous variables equal for all countries
Note: Select 1 to replicate the results in DdPS(2007)
Select 3 to replicate the results in DHPS(2007)
*********************************************************************************
? 1
***************************************************************************
Select 1: To keep the var order specification for the star variables
the same as that given above
Select 2: To change the var order specification for the star variables
for a subset or all countries
Select 3: To set the var order of the star variables equal for all countries
Note: Select 2 to replicate the results in DdPS(2007)
Select 1 to replicate the results in DHPS(2007)
***************************************************************************
? 1
**************************************************************************************
Treatment of deterministics for cointegration analysis
Enter 4 for the case of unrestricted intercepts and restricted trends for all countries.
Enter 3 for the case of unrestricted intercepts and no trends for all countries.
Enter 0 to determine a mix of cases 3 and 4 for each country.
**************************************************************************************
? 3
************************************************************************
Cointegration Tests for the Individual Country VARX* Models
Enter 0 for MacKinnon's asymptotic critical values.
Enter 1 for small sample simulated critical values.
Note: Select 0, to replicate the results in DdPS(2007) and DHPS(2007)
*************************************************************************
? 0
**************************************************************************
Select 5 or 10 percent critical values: enter 5 or 10
Note: Select 5 to replicate the results in both DdPS(2007) and DHPS(2007)
*************************************************************************
? 5
******************************************************
# coint relationships for the individual VARX models
******************************************************
Country # coint
China 1
EuroArea 2
Japan 3
Argentina 2
Brazil 1
Chile 2
Mexico 2
Peru 3
Australia 4
Canada 4
NewZealand 3
Indonesia 3
Korea 4
Malaysia 2
Philippines 2
Singapore 3
Thailand 2
India 2
SAfrica 2
SaudiArabia 2
Turkey 1
Norway 3
Sweden 2
Switzerland 3
UK 2
US 2
*******************************************************************************
Select 1: To keep the # cointegrating relations the same as that given above
Select 2: To change the # cointegrating relations for a subset or all countries
Select 3: To set the # cointegrating relations the same across all countries
Note: Select 1 to replicate the results in DdPS(2007)
Select 2 to replicate the results in DHPS(2007)
********************************************************************************
? 1
.......
epoh 发表于 2011-10-31 17:47
GVAR_Toolbox1.1
User Guide page 37/138, PERFORMING THE GVAR ANALYSIS
***********************
epoh 发表于 2011-10-31 17:47
GVAR_Toolbox1.1
User Guide page 37/138, PERFORMING THE GVAR ANALYSIS
***********************
扫码加好友,拉您进群



收藏
