stata

What types of languages allow programmatic creation of variable names?

淺唱寂寞╮ 提交于 2019-12-11 03:31:57
问题 This question comes purely out of intellectual curiosity. Having browsed the Python section relatively often, I've seen a number of questions similar to this, where someone is asking for a programmatic way to define global variables. Some of them are aware of the pitfalls of exec , others aren't. However, I've recently been programming in Stata, where the following is common: local N = 100 local i = 1 foreach x of varlist x1 - x`N' { local `x' = `i' * `i' ++i } In Stata parlance, a local

How to extract unique strings from a macro?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 03:14:29
问题 I'm trying to automate a reshape using Stata. I have a series of variables measured yearly. They are all named varname_yy , where yy is a number referring to the year of measurement. I managed to extract all the stubs varname_ from the variables and to put them into a macro using the following code: local stubs foreach var of varlist `myvars' { local stub = substr("`var'",1,length("`var'") - 2) local stubs `stubs' `stub' } The problem is that I end up with many repeated stubs in the stubs

Get both dates from each sentence in different variables

六眼飞鱼酱① 提交于 2019-12-11 01:25:14
问题 I now have the following text: Two important events took place on 19/11/1923 and 30/02/1934 respectively. I would like to extract both dates but i want them saved in different variables. I have already tried the regex solution described in a previous question of mine, but in this case it is not working as expected. Is it possible to save both dates? 回答1: It is important whenever you ask a question to provide the code you have tried and a reproducible example. Please read this page for tips on

Select the minimum over blocks of observations

不打扰是莪最后的温柔 提交于 2019-12-11 01:01:52
问题 I am trying to make Stata select the minimum value of ice_cream eaten by every person ( Amanda , Christian , Paola ) so that I end up with just 3 rows: person ice_cream Amanda 16 Amanda 27 Amanda 29 Amanda 40 Amanda 96 Amanda 97 Christian 19 Christian 23 Christian 26 Christian 27 Christian 28 Christian 34 Christian 62 Christian 70 Christian 78 Paola 5 Paola 11 Paola 28 Paola 97 回答1: An answer that avoids creating a new variable: sort person ice_cream by person: keep if _n == 1 回答2: A one-line

How to Aggregate Relational Data in Stata?

瘦欲@ 提交于 2019-12-11 00:49:03
问题 I can't wrap my head around the following Stata programming problem: I have a table listing all car purchases by customers and make: Customer | Make | Price ----------------------- c1 | m1 | 1 c1 | m1 | 2 c1 | m3 | 1 c2 | m2 | 2 c3 | . | . I want to transform this into a table with one observation/row per customer, listing the maximum price paid for every make: Customer | m1 | m2 | m3 ----------------------- c1 | 2 | 0 | 1 c2 | 0 | 1 | 0 c3 | 0 | 0 | 0 How do I achieve this? I know reshape

confirm conditional statement applies to >0 observations in Stata

空扰寡人 提交于 2019-12-11 00:38:22
问题 This is something that has puzzled me for some time and I have yet to find an answer. I am in a situation where I am applying a standardized data cleaning process to (supposedly) similarly structured files, one file for each year. I have a statement such as the following: replace field="Plant" if field=="Plant & Machinery" Which was a result of the original code-writing based on the data file for year 1. Then I generalize the code to loop through the years of data. The problem becomes if in

Stata drops variables that “predicts failure perfeclty” even though the correlation between the variables isn't 1 or -1?

让人想犯罪 __ 提交于 2019-12-10 21:26:31
问题 I am running a logit regression on some data. My dependent variable is binary as are all but one of my independent variables. When I run my regression, stata drops many of my independent variables and gives the error: "variable name" != 0 predicts failure perfectly "variable name" dropped and "a number" obs not used I know for a fact that some of the variables dropped don't predict failure perfectly. In other words, the dependent variables can take on the value 1 for either the value 1 or 0

Double reshape long

假如想象 提交于 2019-12-10 19:45:13
问题 I have the data below: CID CATID PRI11A PRI12A PRI16A PRI17A PRI11B PRI12B PRI16B PRI17B 583234 1 499 633 450 234 995 628 494 639 583820 1 564 987 463 235 432 124 658 54 583820 2 357 786 129 325 98 79 956 453 When I run the command: reshape long PRI, i(CID CATID) j(IDS PRI) The data changes as follows: CID CATID IDS PRI11A PRI12A PRI16A PRI17A PRI11B PRI12B PRI16B PRI17B PRI 583234 1 PRI 499 633 450 234 995 628 494 639 . 583820 1 PRI 564 987 463 235 432 124 658 54 . 583820 2 PRI 357 786 129

Select all possible tuples from a vector in R

岁酱吖の 提交于 2019-12-10 19:34:03
问题 I'm trying to write a program in R that when, given a vector, will return all possible tuples of elements from that vector. For example: tuples(c('a','b','c')) = c('a','b','c'); c('a','b'); c('a','c'), c('b','c'); c('a'); c('b'); c('c') I think it should return a list of vectors. For reference, here is a program that does a similar function in Stata. 回答1: You can use combn : x <- 1:3 unlist(lapply(x, function(n) combn(x, n, simplify=FALSE)), recursive=FALSE) 来源: https://stackoverflow.com

Using Rstudio as an IDE for other programming languages (Stata)

删除回忆录丶 提交于 2019-12-10 14:42:51
问题 I love the Rstudio IDE and the easy point click git(hub) integration. Can I use Rstudio as an IDE for other programming languages? In particular, besides R/Rstudio, I use Stata a lot. Stata is great, but the programing environment (do file editor) is years behind. According to this guide, Stata can be set up to run from other text editors (Emacs, etc). Could I set it up to run from Rstudio? Can Rstudio support syntax highlighting for Stata language? If so can I add a shortcut or command in