List structures in Stan



Stan doesn’t do Bayesian generalized methods of moments. You’re on the wrong list. Please stop repeating the same question.


Then which one software is the best fit for Bayesian generalized methods of moments please mention the right one.


I’m afraid I don’t know any software for methods of moments, generalized or otherwise.


OR you know Jaron ?


the name for this conversation as
Help to fitting (Bayesian Generalized Method of Moment) in any suitable


Please help me about the understanding of following code. which is for Bayesian Generalized method of moment please any one…

//Simple Bayesian Generalized Method of Moments Model
//Essentially this model is the Bayesian analog to a Frequentist GEE model with
//an indepdent working correlation matrix
//the data consists of N 2-person families, thus we do not have independent observations
//however, GEE can be used to conduct valid inference on the mean parameters even given
//the fact that our working correlation matrix (I) is incorrect.

data {
int<lower=0> N; // number of 2-person families
real Y[N2]; // response, ordered by family
real X1[N
2]; // 1 covariate
real N2;
parameters {
real beta0; //intercept
real beta1; //covariate effect
real<lower=0> phi; //variance
model {
real yhat[2];
real sigmak[2];
real sk[2];
vector[4] Fk;
matrix[4,3] D;
matrix[4,4] V;
matrix[3,N] utemp;
vector[3] u;
vector[3] U;
matrix[3,3] u2temp = rep_matrix(0, 3, 3);
matrix[3,3] Sigma;


for(i in 1:N){
yhat[1]= (beta0+beta1X1[2i-1]);
yhat[2]= (beta0+beta1X1[2i]);
D[1,1]=1.0; D[2,1]=1.0; D[3,1]=0.0; D[4,1]=0.0;
D[1,2]=X1[2i-1]; D[2,2]=X1[2i]; D[3,2]=0.0; D[4,2]=0.0;
D[1,3]=0.0; D[2,3]=0.0; D[3,3]=1.0; D[4,3]=1.0;
V[1,1]=phi; V[2,1]=0.0; V[3,1]=0.0; V[4,1]=0.0;
V[1,2]=0.0; V[2,2]=phi; V[3,2]=0.0; V[4,2]=0.0;
V[1,3]=0.0; V[2,3]=0.0; V[3,3]=2phi^2; V[4,3]=0.0;
V[1,4]=0.0; V[2,4]=0.0; V[3,4]=0; V[4,4]=2

//u constains the 3 estimating functions for beta0, beta1, and phi
u= D’*inverse(V)Fk;
u2temp = u2temp + u

//U is the sample mean of the N u’s
//U is asymptotically normal with mean 0 and variance consistently estimating by Sigma
//Bayesian GMM works by applying a normal likelihood to U, and then uses MCMC to estimate //the posterior of all parameters
U[1]=mean(utemp[1,]); U[2]=mean(utemp[2,]); U[3]=mean(utemp[3,]);
Sigma = 1/N2^2 * u2temp - 1/N2 * U*U’;

//pseudolikelihood for GMM (Yin 2009 Bayes GMM paper doesnt use normalizing constant):
//However, model will not fit with or without the normalizing constant…
//target+= -3.0/2.0log(23.14159265359)-0.5log_determinant(Sigma)-0.5U’*inverse(Sigma)U;
target += -0.5


Still don’t know what you mean by GMM, but inverse is usually a bad idea numerically compared to using matrix division. Our built-in densities will be often be better behaved when you can use those.

Notation like uu' isn’t Stan unless uu is a variable.


Thank you very much Sir, for your response
Actually I am a student of MS Statistics at International Islamic
University Islamabad Pakistan.
My research topic is (“Impact of corruption upon economic growth in
Pakistan " Bayesian econometrics Analysis”")

GDP = response variable and (corruption, capital development, financial
development,trade openness ) are regressors.
I have estimate the model through classical Generalized method of moment in
Rstudio software. Now I want to estimate the model through Bayesian
Generalized Method of Moment, I am searching the model coding in (R,
Matlab, Stan, Stata, Eview, and Winbugs) softwares from last six months,
but still I did not find exact command or coding in ang software. Last
month I found that discussion which I mail to you lastly in which you and Jaron
Ben Goodrich and Jonah Gabry fit the Simple Bayesian Generalized method of
moment in Stan software and run in Rstudio in package of (rstan). I will be
waiting of your response, please guide me about my problem as soon as


Our answer remains the same as before: Stan doesn’t do any kind of moment-based methods, so you’re on the wrong list!


Ok Sir thanks replay
Let me clear about one things Please visit to the following link
(Help fitting a simple Bayesian Generalized Method of Moments (GMM) model )
and I am attaching this document also with this mail Please sir check it
and please give me response about this document.

Help fitting a simple Bayesian Generalized Method of Moments (GMM) model - Google Groups.pdf (258 KB)


Sir the command also present in this document and I am mailing to command
also… Please sir I am working on Bayesian Generalized method of moment
from last six months. Please guide me I will be thankful forever…

stan_GEE1_ind.stan (2.36 KB)


You need to spend a lot of time learning the Stan language and how Stan facilitates Bayesian inference by drawing from the posterior distribution. Then it should be apparent how to do GMM with Stan and hopefully apparent that you don’t actually want to do GMM with Stan. Until then, it is unlikely that anyone is going to help you except to refer to answers we have already provided you and to the original GMM poster at .


Thank you sir,
Actually I need the command or coding for Bayesian Generalized Method Of
Moment in any software, I am searching it from last six months but did not
find any command or coding for Bayesian generalized method of moment,
except that stan one that’s why I am contacting with you because of you
people done it. So if you have any material or command and coding in ang
software please mail me I will be very grateful. Please sir…


How it is coded depends on the problem. You need to start by writing a function in the Stan language that inputs the parameters and data and outputs the matrix U and Sigma as in section 2.1 of the Yin paper, which is the same as you would do with frequentist GMM. From there, it is easy with Stan, but the challenge is you have to learn the Stan language and how to write functions in it. This is all explained in the user manual.


Thank you sir for urgent response,
If I want to edit my data and variables into Jaron command for Bayesian
Generalized Method of Moment which is already fitted. Is it possible?


Hello sir I hope you will be fine.
Please sir give me a readymade coding for Bayesian Generalized Method of
Moment, through which I estimate my econometric model parameters I will be
very grateful.


That’s not going to happen.


Please sir my research work is stop from last six months because of did not
find the code or command for Bayesian generalized method of moment please
sir guide me I will remember this kindness forever.


In 6 months, you could have learned the Stan language, translated the key parts of frequentist GMM into Stan, and gone on vacation for five months. We aren’t here to write somewhat dubious models for people who don’t want to invest the time and effort to do it themselves.


thank you sir,
Lite me clear you about my six months works, An initial stage I am
searching it winbugs, Eview and other basic software but nothing to find in
these software. Then I started searching it in R language only papers I
had found and after that I search in matlab for last month but there is no
one to do it with command. And lastly I searched it in STAN here I found
that one coding which have being done for two simple linear model.
Please sir give me a suggestion that how I do it please sir only a