This code fragment page shows an example using Mata optimize to estimate a confirmatory factor analysis model. The input for the program is the covariance matrix shown below which was…
Read More
Search Results for: stata
Compute Adjusted Values from Cox Model using Mata | Stata Code Fragments
Version info: Code for this page was tested in Stata 12.1. This code fragment page shows an example using Mata to write a function that calculates adjusted values from a…
Read More
Reading data from Stata into Mata | Stata Code Fragments
/* input data into Stata */ input y x0 x1 x2 7 1 2 1 15 1 4 4 20 1 3 7 15 1 6 3 12 1 5…
Read More
Simulating Discrete (Geometric, Poisson and Zero-Inflated Poisson, Negative Binomial and Zero-Inflated Negative Binomial) Random Variables | Stata Code Fragments
Geometric Random Variable: It can be shown that a Geometric random variable can be simulated using the following argument (int(ln(u)/ln(1-p)) + 1) where u is a uniform(0,1) random variable and…
Read More
Compute Dispersion using Mata | Stata Code Fragments
Version info: Code for this page was tested in Stata 12.1. Researchers are sometimes interested in studying not just the effects of ethnicity, but the effects of the heterogeneity in…
Read More
Displaying the hazard ratio of different baseline characteristics by a dichotomous variable | Stata Code Fragments
The scheme used for this plot can be downloaded by –search lean scheme– from within Stata. This example has a few steps. The first step is to run all the…
Read More
Computing the Sum Difference Between Two Latitude and Longitude Points using Mata | Stata Code Fragments
Version info: Code for this page was tested in Stata 12.1. This code fragment page shows an example using Mata to write functions and loop through a dataset to calculate…
Read More
Generate Anonymous Keys using Mata | Stata Code Fragments
Version info: Code for this page was tested in Stata 12.1. This code fragment page shows an example using Mata to write a function that generates anonymized keys for wide…
Read More
Graphing interactions of two continuous variables using postgr3 | Stata Code Fragments
This example uses the hsb2 data file to illustrate how to graph an interaction of two continuous variables. This is based on the techniques illustrated in these books. Multiple Regression:…
Read More
Graphing means and confidence intervals by multiple group variables | Stata Code Fragments
The code below shows how to plot the means and confidence interval bars for groups defined by two categorical variables. This type of plot appeared in an article by Baker,…
Read More
