stata

Stata counting substring

旧时模样 提交于 2019-12-12 01:59:51
问题 My table looks like this: ID AQ_ATC amountATC . "A05" 1 123 "A05AA02" 2525 234 "A05AA02" 2525 991 "A05AD39" 190 . "C10" 1 441 "C10AA11" 4330 229 "C10AA22" 3100 . "C05AA" 1 441 "C05AA03" 130 The count for the full 8-character AQ_ATC codes is already correct. The shorter codes are unique in the table and are substrings of the complete 8-character codes (they represent the first x characters). What I am looking for is the count of the appearances of the shorter codes throughout the entire table.

How can I import .eps in Mathematica without losing the text?

冷暖自知 提交于 2019-12-12 01:58:18
问题 I am trying to import a histogram produced by Stata as an .eps file into Mathematica , but it does not display axes' labels. That is, for some reason, Mathematica does not import .eps as but rather transforms it. How can I avoid that? As of now, I am using plain Import["~/hst.eps"] 回答1: I had a similar problem with LateX and a pdf graph recently, which also manifested itself with the eps version. I wound up modifying the user-written graphexportpdf and things seemed to work out. Perhaps you

Entering subsets of variables in Stata commands

有些话、适合烂在心里 提交于 2019-12-12 01:26:42
问题 I would like to enter groups of variables into a Stata command, but can't find a way to do so. E.g. In a factor analysis, with a set of 41 variables, I would like to exclude the 5th, 33rd and 35th, but include the rest. Should it be something like: factor x1-x4, x6-x32, x34, x36-41, factors(5) pcf 回答1: Your example calls up a factor analysis. Let''s keep with that. If your variables are indeed at least those named out of x1 through x41 then factor x1-x4 x6-x32 x34 x36-x41 could be legal. Note

Stata year-quarter for loop

半世苍凉 提交于 2019-12-12 01:20:03
问题 I am trying to create a loop in Stata. I run a model for the data <= year and <= quarter. Then predict one year look ahead. That is the model is run all time points upto the loop, while the prediction happens in the next quarter out of sample. So my question is how do I handle so that when yridx = 2000, and qtr = 4, the next quarter inside the loop look ahead would be year = 2005, and year = 1. foreach yridx of numlist 2000/2012 { forvalues qtridx = 1/4 { regress Y X if year <= yridx and qtr

generating bootstrap standard errors for large number of scalars

时光总嘲笑我的痴心妄想 提交于 2019-12-11 23:52:21
问题 Suppose I have four scalars: call them dea_1 dea_2 dea_3 dea_4 . They are output from a program samprogram (not shown here). Now I use the bootstrap command in Stata with these scalars to get bootstrapped standard errors. set seed 123 bootstrap dea_1=r(dea_1)dea_2=r(dea_2)dea_3=r(dea_3)dea_4=r(dea_4), reps(100): samprogram This is fine but in my original program, I calculate 30 scalars, dea_1 dea_2 ... dea_30 . Now I want to avoid writing each of these 30 scalars in the bootstrap command and

Stata: Elements of variable

廉价感情. 提交于 2019-12-11 21:25:28
问题 How can I edit every 2nd value of a variable? My code is: set obs 100 gen u = invnorm(uniform()) forvalues d = 1/50 { gen u[2*d] = u[2*d] + 1 } What's wrong with my code? 回答1: The syntax for generate doesn't allow anything except a storage type and variable name (and a label name, irrelevant here) after generate and before = . This is clearly indicated by the help file. You don't need a loop here. If you want to work on observations 2, 4, ... then gen new_u = u + 1 if mod(_n, 2) == 0 selects

Stata: combining regression results with other results

自作多情 提交于 2019-12-11 21:10:58
问题 I am trying to replicate some results from a study. therefore often i need to compare my regression results with results from the study that i'm trying to replicate. I have been manually combining my esttab results with the study results in excel. this however is tedious since i'm working with lot of variables. I was wondering whether there is a way to store the study results and then calling them to go next to my regression results. I tried storing them as scalars and calling them using

Stata: replace dummy for multiple observations

牧云@^-^@ 提交于 2019-12-11 18:13:11
问题 Title might be misleading. I have a longitudinal dataset with a dummy ( dummy1 ) variable indicating if a condition is met in a certain year, for given category . I want this event to be taken into account for the next twenty years as well. Hence, I want to create a new dummy ( dummy2 ), which takes the value 1 for the 19 observations following the observation where dummy1 was 1, as well as that same observation (example below). I was trying to create a loop with lag operators, but failed to

Random lottery numbers from macro to variable

旧城冷巷雨未停 提交于 2019-12-11 18:01:31
问题 I have the following lottery numbers in a macro: global lottery 6 9 4 32 98 How can I simulate a variable with 50 observations, where each observation is randomly obtained from the numbers stored in the macro? The code below produces an error: set obs 50 global lottery 6 9 4 32 98 g lot=$lottery invalid '9' r(198); 回答1: Here are two similar methods: clear set obs 50 set seed 2803 local lottery 6 9 4 32 98 * method 1 generate x1 = ceil(5 * runiform()) tabulate x1 generate y1 = . forvalues j =

What's the equivalent of R sample function in Stata

孤街醉人 提交于 2019-12-11 17:50:23
问题 I have a basic question about Stata. I have programming experience in R but I've started a new job where Stata is the main language. I'm currently diving into Stata on my own and sometimes it's hard to understand how to do simple things. I've trying to get 5 random numbers between 3 and 50 but without success. In R, any of these would work: floor(runif(5, min=3, max=50)) 16 39 11 11 5 # output sample(3:50, 5, replace=TRUE) 28 13 5 36 19 # output But I'm not sure how to do this in Stata,