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 votes
0 answers
10 views

Stata loop merge command

Here is my code: ''' foreach i in incident month suspected_drug OFFENSE { import delim NIBRS_`i'.csv, clear save NIBRS_`i'.dta, replace clear } } //A third loop this time to merge data together ...
0 votes
1 answer
33 views

OpenStreetMap Stata Geocoding (JSON)

I am not too familiar with Stata's json capabilities. Would it be possible to rewrite this python script in Stata? import url import requests data = data[['Locality']] def geocode2(locality): ...
-2 votes
0 answers
12 views

Running API Routing in STATA, received "invalid credentials" error

I am running API driving distance routing through HERE.com using Stata. I keep receiving an error that reads "There seems to be an issue with the credentials of your HERE application: https://...
0 votes
0 answers
23 views

Create a matrix with strings and numeric values in memory

I want both string and numeric values in a matrix. I do not want to create a new dataset because in my real code, I have to keep the dataset loaded, so I have to fill this matrix with numeric and ...
0 votes
0 answers
13 views

Intercept in fixed effects regression with feols

How do I get the intercept from a fixed effects regression using fixest::feols? library(fixest) feols(Sepal.Length ~ Sepal.Width | Species, iris) #> Estimate Std. Error t value Pr(>...
-1 votes
0 answers
12 views

How to add notes to maps in stata

may someone help me with adding notes to maps generated with the command spmap in Stata please? I tried to search in help spmap, but I didn't find anything, not even "addnote" or some ...
0 votes
2 answers
2k views

coefplot: Putting names of regressions on y-axis

The following code will generate a coefficient plot: sysuse auto, clear regress price mpg trunk length turn if foreign==0 estimates store D regress price mpg trunk length turn if foreign==1 estimates ...
0 votes
0 answers
12 views

R two-way ANOVA diferent from Stata except for interaction

I am taking a statistics class and we are supposed to be using Stata but are free to use whatever software we like, so I am teaching myself R. So far, I've been able to replicate homework answers but ...
0 votes
1 answer
20 views

Skip non existent data files in import loop

I have daily data files over weekdays (thus there is a gap during weekends, month's end etc) that I'm trying to import through several loops in Stata. I want to skip if the file is non existent and ...
0 votes
0 answers
30 views

Stata randomly produces "program error: code follows on the same line as close brace" only sometimes

I have some Stata code that sometimes produces the error "program error: code follows on the same line as close brace". Other times it runs. What is strange is that the code will run, maybe ...
0 votes
2 answers
29 views

Finding standard deviations of columns of a matrix

Suppose I have a matrix generated by the following code: matrix A = (1,2\2,5\.,7\.,10\.,2\.,13) I want to find the standard deviation of each column of the matrix (there are two in this example, so I ...
-1 votes
0 answers
41 views

combining IRT category characteristic curves with a specific legend

I am plotting category characteristic curves from a polytomous IRT model and I'm having trouble combining these graphs and adding a specific legend. Other examples online show ways to have the ...
1 vote
1 answer
53 views

Disregard from part in import loop

I have several data files that I want to import into Stata with 4 different loops in the following way import delimited "path\`x´name`i´`j´`k´.T0653248.csv clear" where x is a foreach loop ...
0 votes
1 answer
28 views

Computing average in randomization inference

Suppose I have the following simulated data: set obs 10 set seed 125 gen tau = runiform() Assume that 3 out of 10 observations are 'treated', but we do not know which observations are treated. I want ...
0 votes
0 answers
16 views

Using a NLSY97 dataset, values in multiple courses from transcript data for the same year for the same participant, Stata

I want the GPAs for whatever English class and whatever Math class an NLSY97 participant took in 10th grade in 1998. However, after building a dataset with the following variables and importing into ...
6 votes
2 answers
1k views

R - Testing equivalence of coefficients in multivariate multiple regression

I'm trying to conduct a multivariate multiple regression analysis. Fortunately, I've found an excellent page demonstrating how to do so in Stata: http://www.ats.ucla.edu/stat/stata/dae/mvreg.htm The ...
24 votes
3 answers
11k views

Any Python Library Produces Publication Style Regression Tables

I've been using Python for regression analysis. After getting the regression results, I need to summarize all the results into one single table and convert them to LaTex (for publication). Is there ...
0 votes
1 answer
33 views

Sorting a collaborative database

I'm working through a database with several repeated IDs entries and unique information per row as such ID country A1 AT A1 BE A2 CZ A3 US A3 UK A4 NZ The same ID and different country implies ...
0 votes
1 answer
19 views

Replacing values in specific variable for specific rows

I have a data frame in Stata that has an ID variable with some rows missing id values. I want to systematically assign values to these rows with missing values by assigning ids that increase in value. ...
0 votes
0 answers
23 views

How to insert a piece of python code into Stata's .ado file?

I am writing a Stata file named mycode.ado. The basic structure of it is as follows: program define mycode di "I am going to print a random number get from random.org" python: import ...
0 votes
1 answer
28 views

How to make statement case insensitive when uploading a dta file with specified columns?

I want to loop through different files: forvalues y=2014/2022 { use var1 var2 var3 using "file_`y'.dta" save "file2_`y' } However, some of the files have var names VAR1 VAR2 ...
0 votes
1 answer
37 views

Introduction to local macros and foreach loops not replicable?

I’m doing a Stata tutorial to try and catch up on macros, loops and data visualization. I tried replicating the syntax patterns from different tutorials using my own data, and Stata insists that the ...
0 votes
1 answer
24 views

How to append all the files of a subfolder in stata

I work from two computers, a desktop and a laptop, so usually my code goes like this: global laptop "laptop/pathToFolder" global desktop "desktop/pathToFolder" cd $laptop * make ...
1 vote
0 answers
41 views

Produce Predictive Margins in Statsmodels Output for Logistic Regression

I've used the get_margeff() function to try to generate margins for a logit model I've run. Here is the data and code: model_5a_1 = smf.logit('''fluid ~ C(examq3_n, Treatment(reference = 2.0)) + C(...
0 votes
2 answers
21 views

Randomizing only some observations in Stata?

My dataset is a larger version of this section: ID Year Units Price Type Carrots 2009 12312 3.25 V Carrots 2010 10891 2.75 V Carrots 2011 13232 3.50 V Carrots 2012 9302 4.50 V Onions 2011 728992 ...
1 vote
1 answer
52 views

Capture a Stata-style log in R (comments, commands, and output)

I'm hoping to use R to capture a log that shows comments, commands, and output from the script. txtStart() from TeachingDemos gets close, but it omits comments. This script library(TeachingDemos) ...
1 vote
1 answer
28 views

Exporting specific Stata output from ivreg2 to LaTeX

I am trying to export results of the Sanderson-Windmeijer multivariate F test of excluded instruments from Stata. Consider the following working example: use http://fmwww.bc.edu/ec-p/data/wooldridge/...
-1 votes
0 answers
25 views

twoway bar graph - how to make the bars touch the bottom- plotregion doesn't work for me

Here is my plot: barchart with confidence intervals and my code: twoway (bar meanhomemp ethnisex if SEX==1) /// (bar meanhomemp ethnisex if SEX==2) /// (rcap hihomemp lohomemp ethnisex), /// legend(...
0 votes
0 answers
36 views

Ivreg and clustering in R

Struggling to get clustering to work with ivreg in R. Clustering is based on a variable with 255 unique values. I've been trying to translate this stata code to R ivreg2 X (Y = A?) iv1 iv2 iv3 if ...
0 votes
1 answer
471 views

repeated time values within panel (r451)

I'm really new on Stata and I'm trying to work with a panel data. I know that, to set a panel data, one uses xtset id year, but when I try to use this command Stata returns the error "repeated ...
0 votes
1 answer
35 views

inlist() function

I have a sample and one of the questions is education level. I am trying to find the number of people from the sample who have some form of degree as their highest level of education. I try the below ...
0 votes
1 answer
34 views

How to “use” files with names that include certain text?

I'm importing files through a loop: forvalues y=2010/2022 { use "file`y'V1.dta" [making changes] save “file`y'.dta” } Problem is that some of the filenames have "V2" ...
0 votes
1 answer
16 views

Keeping first event between two ID groups in Stata

I am trying to keep the first event between two ID groups in Stata as well as the rest of the events. ID1 ID2 Event Year 1 2 1 2021 1 2 1 2022 2 3 1 2021 2 3 1 2022 2 ...
0 votes
1 answer
50 views

Stata Store Slope

STUDENT TIME SCORE 1 1 9 1 2 11 1 3 7 2 1 8 2 2 6 2 3 14 2 4 11 3 1 14 3 2 10 3 3 9 4 1 14 4 2 6 mixed SCORE || STUDENT:TIME I wish to estimate ...
0 votes
1 answer
308 views

Removing shaded area title from the graph in Stata

I built this graph but unable to remove/rename the label of the shaded area. How to do both? line smunits timenew if maxcumul==158453||area smunits timenew if timenew < 16.3&maxcumul==158453, ...
0 votes
1 answer
56 views

Stata twoway: How to center x-axis title with by() option

When I create this twoway graph using the by() option, the x-axis title is not centered on the inner plot region (it is centered relative to the whole figure). This does not look good, especially with ...
-2 votes
1 answer
3k views

How can I combine variables in Stata

I have a Stata dataset containing variables: A1, B1, A2, B2, A3, B3,..., A15, B15. All variables with A are gender and those with B are the corresponding ages. How can I combine all variables into ...
0 votes
1 answer
8k views

Plotting linear graphs from dummy variables in Stata

I want to plot linear graph of the fraction of 1's and 0's I have in my main variable of interest by gender. I know how to do that using bargraphs, either using count or mean but these commands do ...
0 votes
2 answers
24 views

How to update observations with from 2 variables

I have a dataset that looks like this in Stata: Place year value a 2000 b 2000 c 2000 100263 a 2001 100261 b 2001 100262 c 2001 100263 a 2002 b 2002 c 2002 I want the values to remain the ...
0 votes
1 answer
53 views

Complex survey data matching and cleaning

I'm trying to match some super complex personal identifiers across ~6000 survey responses, currently stored in a big Excel doc. In essence, respondents participated at time 1 and 2. They were each ...
-1 votes
2 answers
57 views

Create month dummies based on start and end date (in R or Stata)

structure(list(id = c(1, 1, 2, 2, 2, 2, 3, 4, 4, 4, 4, 5), `start month` = c(1, 4, 5, 8, 12, 11, 10, 3, 5, 6, 2, 1), `start year` = c(1999, 2018, 2017, 2019, 1980, 2019, 2016, 2020, 2022, 2019, 2015,...
0 votes
1 answer
16 views

How to esttab when treatment variables has different names

I am running a dynamic DiD in Stata. I have to check the robustness of the geographical size of my treatment area and for that I run regressions where I interact the year with a treatment variable. ...
0 votes
1 answer
26 views

Stata: make predictions for new dataset using results of mvprobit (multivariate probit model)

I have estimated a multivariate probit model with four equations using the mvprobit command in Stata. The four dependent variables are: does a farm adopt rainfed farming (yes/no), surface irrigation, ...
0 votes
1 answer
2k views

Export ATT result after psmatch2 command

I need to export the output from the psmatch2 community-contributed command in Stata. For example: psmatch2 treatment var1, neighbor(1) out(depvar) where treatment is a dummy variable, var1 is the ...
0 votes
0 answers
50 views

PSM: reproducing results from kmatch with psmatch2 in Stata

I am working on Propenstiy Score Matching with Stata 17. I use userwritten command kmatch to automatically estimate the bandwith for kernel matching, but I prefer the balancing outputs of psmatch2. ...
0 votes
0 answers
9 views

How do I use a GLM with longitudinal data to get a treatment effect at a specific time point in Stata?

So I want to use the mixed command. I have 3 different time points. I want to do a regression at time point 3 to see the effect of 'group' on 'score'. I tried to create a variable for score when time=...
0 votes
1 answer
17 views

changing a list of variable names in a global macro to factors

I would like to change a list of variable names in an existing global macro to factors without generating a new global macro, i.e. changing the contents of the existing macro For example, I have the ...
-1 votes
0 answers
12 views

How do I create a table like this using a data file?

this is the table that i want to achieve In Stata I tried using the command .summarize x1 x2 by(Catastrophic_plan) statistics(mean sd n) -> this give me n for all x variables but I only want the n ...
0 votes
0 answers
19 views

Converting data from long to wide, and keep specific variables

I have a very large dataset in Stata with more than 1000 variables. How can I convert this data from long to wide and: keep specific variables from the dataset. Keep all the variables. I have tried ...
1 vote
3 answers
56 views

Delete observations outside of a range (in R or Stata)

structure(list(id = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), month = c(201701, 201702, 201703, 201704, 201705, 201706, 201707, 201708, 201809, 201810, 201811, ...

1
2 3 4 5
89