Questions tagged [stata]

Stata is a commercial, general-purpose statistical software. It is available for Windows, Mac and Unix systems. Stata's capabilities include data management, statistical analysis and graphics. ------------------------------------------------------------ IMPORTANT: Click 'Learn more' for advice on how to ask high quality Stata-related questions on Stack Overflow.

Filter by
Sorted by
Tagged with
1 vote
1 answer
19 views

Retrieving the Weight Variable Name Following svyset

I'm working on a program in Stata that requires the weighted percentile (I'm inclined to have the user set up first svyset instead of allowing them pass the weight variable in my command), and I need ...
Maximiliano Rodriguez's user avatar
0 votes
0 answers
16 views

Mediation analysis with multiple mediators

I am doing a longitudinal mediation analysis in Stata with one IV (categorical), 3 MV (continuous) and one DV (continuous). The 3 MVs are correlated. Now, in a simple mediating model like the ...
Ishwarya Balasubramanian's user avatar
0 votes
1 answer
25 views

value weighted "xtile" does not give close to equal division (Stata)

I'm using the following Stata code to calculate value weighted (wt) groups based on a variable called x: egen q = xtile(x), by(year) nq(2) weights(wt) However, the code above gives me very unequal ...
jgr's user avatar
  • 127
1 vote
0 answers
18 views

Matrix define works also with "==" operator, is it a bug?

The syntax for matrix substitution is (help matrix substitution): matrix A[r,c] = ... where r and c are numeric scalar expressions. Description If the matrix expression to the right of the equal sign ...
Enrico's user avatar
  • 17
1 vote
1 answer
60 views

How to get out-of-sample predictions for specific subgroups, in Stata?

I have a mixed effects logistic regression model: quietly melogit y i.x1 i.x2 || x3: Variable x1 is coded 0/1. I create the predicted probabilities for both values of x1: margins x1 Then I obtain ...
Rene's user avatar
  • 91
-1 votes
1 answer
28 views

Create a year variable to establish a panel variable-

I have 3 variables in Stata that I want to make into a panel variable, f4hi. Currently, they are called f4hi97, f4hi98, and f4hi99. I want to pull the last two digits from these to create a separate ...
Ivey's user avatar
  • 1
0 votes
0 answers
26 views

Is there a way to display cell content in two rows?

I'm currently working with Stata to write my bachelor thesis, and I've encountered a problem with formatting table 1 (descriptive statistics) I can't seem to solve. I'm researching the effects of ...
lighterra's user avatar
0 votes
0 answers
23 views

irt hybrid model predict latent estimate using bayesian method

I'm having some problem about irt prediction model. When i use irt hybrid model, it cannot predict the latent value even it has successfully converge during the irt model processed. It contain binary ...
梁聖宇's user avatar
0 votes
0 answers
57 views

xtsktest - overwriting the input model

I am working with panel random effect models and I need to perform Galvao test to check the normality of residuals (even if I am aware that normality shouldn't be an issue as explained by Professor ...
Edoardo Mattioli's user avatar
0 votes
0 answers
36 views

post hoc test following linear mixed effect regression: stata code?

I am trying to figure out the code to do a post hoc test (Bonferroni adjusted) in Stata following my linear mixed effects model. I believe the margins command can be used? Does anyone know how I can ...
Sarah's user avatar
  • 43
0 votes
2 answers
43 views

pivot longer by looping over certain columns

I have the following data which belongs to my darts league in wide format structure(list(home_team = c("Art of Dart", "Art of Dart", "Art of Dart", "Art of Dart&...
Emre Toros's user avatar
-3 votes
0 answers
54 views

How to transfer this panel data from Stata to R

I am currently transitioning from Stata to R for my data analysis, and I've encountered some challenges in replicating the results I typically obtain from Stata when using R. I've included my Stata ...
Amy Xiejing's user avatar
0 votes
1 answer
49 views

How do I use Interaction variables in a multinomial probit model?

I'm doing an econometrics project with stata where I'm looking at the impact of individual's BMI (body mass index and Height (called height 5 as I divided the height by 5 so I could interpret by ...
econstu123's user avatar
0 votes
0 answers
26 views

Running Stata18 (SE version) in Visual Studio Code

I have been trying to run some STATA do-files from Visual Studio Code on a laptop with Windows 10. I followed the steps detailed in the stataRun REARME and also tried with the recommendations from ...
Luiscr-22's user avatar
0 votes
0 answers
12 views

High t statistic with high p value for same variable? [migrated]

I am trying to do a difference in difference model to compare two cities' police departments' uses of force after treatment from a consent decree. When I run the model with clustered standard errors, ...
Drew Godsell's user avatar
-1 votes
0 answers
18 views

Pairwise comparisons of Pairwise comparisons in Stata

I am trying to see if it is possible to determine if there is a significant difference between pairwise comparisons from the stata margins command. Essentially, I would like to compare pairs of ...
Julia Wojciechowski's user avatar
0 votes
0 answers
20 views

How to group Stata coefplot (recast as bar) bars together by dependent variable?

I am trying to make a plot in Stata that examines the probit regression for 7 dependent variables (each observation having a value of 0 or 1) based on a single categorical variable. My code is quite ...
treich47's user avatar
0 votes
1 answer
39 views

lag.plot in R as in Stata

I want to plot a scatter of the residual and its first-order lag, i.e., plotting $(e_{t-1},e_{t})$, as well as adding the least square line in Stata. My little demo is from Example 2.3 The U.S. ...
John Stone's user avatar
-1 votes
1 answer
30 views

loops with replace within a variable

I have a variable in Stata for year of birth. Some values are 77, 1986, 66, 2000, 88, 99, 70, 1995 so I need to replace values such as 88, 70, 66 to be 1988,1970,1966 and so on. How should I do this ...
Anushka Mullick's user avatar
-1 votes
1 answer
38 views

How can the average employment value be calculated or generated for three types of values within a variable?

I want to generate or calculate the average employment value for all three age groups (15+, 15-24, 25+) for each year for each country (five countries) for male and female. What are the exact command ...
Zeinab 's user avatar
0 votes
0 answers
40 views

Stata JDBC PostgreSQL mystery bug

I've launched a cloud PostgreSQL database at my organization and have had a few users test it. I thought it best to have my users use JDBC rather than ODBC in Stata to connect to the DB, as it saves ...
snowpeak's user avatar
0 votes
0 answers
20 views

Stata merge with duplicates in both master and using

Say that I have two datasets: clear all set obs 4 gen a = _n<3 gen b = "b_"+string(_n) gen n = _n tempfile data1 save `data1' clear all set obs 4 gen a = _n<3 gen c = "c_"+...
bill999's user avatar
  • 2,207
0 votes
0 answers
29 views

Transferring svyset from Stata to R

I have a survey project in Stata but I want to transfer this into R. This code in Stata sets the weighting: svyset sitename [pweight=wgt], poststrata(strata) postweight(popsize) and then this code ...
Vicki Latham's user avatar
0 votes
0 answers
21 views

How to generate a variable for matched observations

I'm using Stata to analyze some clinic data. In my dataset, I want to match 5000 treated observations each with more than 1 untreated observation. And I want to generate a dummy variable to indicate ...
Greenhill's user avatar
  • 135
0 votes
0 answers
7 views

How to run a χ2 test or Fisher's exact test between independent var (treatment A vs. B) and dependent var (diarrhea, graded from 0 to 5)

I run the sentence: tabulate diarrhea treatment, chi2 column exact expected But what I'd like to obtain is the following: ?% grade 0 for treatment A vs. ?% grade 0 for treatment B --and p value ?% ...
user22236177's user avatar
0 votes
0 answers
23 views

Replicating Stata sureg and Wald test results in R

I am trying to replicate the results of a Stata code snippet that performs a sureg regression and calculates p-values of a Wald test. Here's the Stata code I'm trying to replicate in R: sureg (y_1 a b ...
giampaolo mariani's user avatar
3 votes
1 answer
96 views

pandas StataWriter: Writing an iterator for large queries; .dta file corrupt

I'm trying to subclass the pandas StataWriter to allow passing a SQL query with chunksize to avoid running out of memory on very large result sets. I've gotten most of the way there, but am getting an ...
FlipperPA's user avatar
  • 13.8k
0 votes
0 answers
39 views

Bias estimation of the lagged variable coefficient

We use a data generating process to create a panel data set and now we want to include a lagged variable and see the effect of the bias for different time periods. The data for the first year of the ...
George's user avatar
  • 1
1 vote
1 answer
39 views

Logical Subsetting in Mata

In Mata (the matrix language in Stata), I am trying to find logical subsetting or that's equivalent. Consider that we have a matrix: clear all version 18 mata: tmp = (-0.5, 1 \ 5, -5) Here, I want ...
MinChul Park's user avatar
0 votes
1 answer
39 views

estout loop with different regressions results

I want to easily select a regressor among a list of regressor that negatively affects the dependent variable and minimizes the BIC criterion within a loop. To do so, I would like to present all the ...
ele_al_12's user avatar
0 votes
1 answer
37 views

Calculate quantiles with bootstrapping in Stata

I have data on income and want to calculate percentiles using bootstrapping as well as population weights. What I did so far (and what worked): collapse (p10) p10 = income /// (p90) p90 ...
mostlyharmless563's user avatar
-1 votes
1 answer
35 views

ARIMA model in Stata

I am trying to calculate in Stata a monthly autoregressive time-series measuring whether avg_happy changes with output. For now I tried using the code: arima avg_happy, ar(1) ma(1) but I keep getting ...
daviddupont's user avatar
0 votes
0 answers
25 views

Stata error when using wild bootstrap command

I'm getting an error when I use the following command in Stata: wildbootstrap regress y x1, cluster(area) rseed(12345) where y is my dependent variable, x1 is a vector of independent variables, and ...
Angus Macdonald's user avatar
0 votes
0 answers
14 views

How to esttab the weakiv test result?

I want to esttab the weakiv result in table But I try many ways but cannot show the result in Stata. What's the problem? Here is sample code. sysuse auto, clear eststo:ivreg2 price (displacement=mpg) ...
janeluyip's user avatar
0 votes
1 answer
57 views

.to_stata(). Big data file causing python to crash

I have in Pandas a dataframe with about 7 million rows and 1600 columns. I've successfully exported the file to Feather, but I would need to get into Stata. I've been using to_stata() a lot in my code,...
Alex Günsberg's user avatar
-1 votes
1 answer
34 views

Stata: How to separate addresses in a string variable

I have a string variable that contains addresses. How do I separate them so that I have address1, address2, ..., and so on? For example: 7400 e roosevelt blvd # c201,philadelphia, pa 19152,7400 e ...
Rebecca's user avatar
  • 11
1 vote
1 answer
33 views

Extracting/filling year and monthly variables in Stata

[] Above is my data in Stata. The data are xtset using incidentCode and monthlyDate. I need to either interpolate or fill or extract missing values for the variables called, year and month. The ...
Kathryn Overton's user avatar
0 votes
1 answer
57 views

Why does the `syntax` command get weird with string variables in Stata?

Let's say I make the following simple program: program define test_prog1 syntax varname =exp display `"`varlist' `exp'"' end And I run it with the following commands in the Stata ...
Frank's user avatar
  • 564
0 votes
2 answers
53 views

How can I write this loop in Stata correctly?

I am trying to create a loop in Stata that will create 19 new variables. The code that is used to create two of these variables is: generate kode_saksinnhold_1 = 1 if kode_saksinnhold == "1" ...
MB Hemler's user avatar
-1 votes
1 answer
25 views

How to convert a vector into a matrix in Mata?

R's equivalent of what I want to do is like below: > tmpv <- seq(1, 12, 1) > tmpm <- matrix(tmpv, ncol = 3, byrow = TRUE) > tmpv [1] 1 2 3 4 5 6 7 8 9 10 11 12 > tmpm ...
MinChul Park's user avatar
0 votes
0 answers
9 views

Outputting results from ksmirnov from Stata into Excel

I have results from a ksmirnov test in Stata and want to output them, ideally using something from the estout suite. Any advice? I've tried the following but it hasn't worked out well: ksmirnov ...
book457's user avatar
0 votes
0 answers
48 views

How to find where a built-in program/command is defined in Stata?

If I want to find where a built-in program/command in Stata (e.g. generate) is defined and/or being loaded from, is there a way to query an interactive Stata session to find out? Or do I have to ...
Frank's user avatar
  • 564
0 votes
1 answer
56 views

Linear Programming in Mata with panel data - looping over individuals, specifying objective function

I try to use linear programming in Mata. I would like to assign an education category (z,s,v = low, middle, high) to each individual according to probabilities obtained previously by odered probit. I ...
Katarina V's user avatar
0 votes
2 answers
26 views

Calculating group score in Stata

I have three variables: Household_ID, Age and Score. My goal is for Stata to calculate a score (for each household) based on the ages of household members in the following way: Add 0.5 if member is ...
mostlyharmless563's user avatar
-1 votes
1 answer
55 views

Reshape data from wide to long (Creating Panel Data)

I downloaded data from data stream Refinitiv. The data is in wide format which resulted in too many variables (761). I only want to form 8 variables. How can I do that in Stata? enter image ...
neef's user avatar
  • 1
0 votes
1 answer
44 views

R merge question: How to perform 1:1 similar to Stata?

Lets say I have these two tables: df1 <- data.frame( Symbol = c("A", "A", "B"), Quant = c(10, 10, 10), ID1 = c(1, 2, 3) ) df2 <- data.frame( Symbol = c(&...
Azamat Sadikov's user avatar
0 votes
1 answer
13 views

Stata foreach not generating output

foreach x in 1:3 { gen VAR`x'TEST = . } I wish to create loop that makes VARIABLES: VAR1TEST, VAR2TEST, VAR3TEST but this generates only a variable called V1
bvowe's user avatar
  • 3,140
0 votes
1 answer
43 views

Using python from a specific virtual environment in stata?

Hello everyone I am trying to execute some Python code in a project where most of the code is in Stata. The project has its own virtual environment where I installed only the Python packages I really ...
Guido Bongioanni's user avatar
0 votes
1 answer
134 views

Coefplot-Graph point estimates and confidence intervals from different regressions

In Stata, I am running the same regression 5 times, with each regression covering a separate time interval. I previously have stored the coefficient of interest after each regression like so: local ...
Joshua Scott's user avatar
0 votes
2 answers
35 views

Stata regression to find out treatment effect

I want to run a regression to find out which effect my treatment, open goal setting, had on the step count made. I have the following variables: before (average of the steps before the treatment/goal ...
Linda's user avatar
  • 1

1
2 3 4 5
93