stata

Stata: Using egen, anycount() when values vary for each observation

允我心安 提交于 2019-12-11 13:09:22
问题 Each observation in my data presents a player who follows some random pattern. Variables move1 up represent on which moves each player was active. I need to count the number of times each player was active: The data look as follows (with _count representing a variable that I would like to generate). The number of moves can also be different depending on simulation. +------------+------------+-------+-------+-------+-------+-------+-------+--------+ | simulation | playerlist | move1 | move2 |

Pandas - Create a table with a “dummy variable”

坚强是说给别人听的谎言 提交于 2019-12-11 12:19:07
问题 Let's say I have this dataframe id | car | sex | income ------------------------------- 1 | European | Male | 45000 2 | Japanese | Female | 48000 3 | American | Male | 53000 Is there an easy way to create this one (using pandas) ? | id | car | choice | sex | income 1.| 1 | European | 1 | Male | 45000 2.| 1 | American | 0 | Male | 45000 3.| 1 | Japanese | 0 | Male | 45000 | ---------------------------------------- 4.| 2 | European | 0 | Female | 48000 5.| 2 | American | 0 | Female | 48000 6.|

Stata: calculating growth rates for observations with same ID

荒凉一梦 提交于 2019-12-11 11:47:54
问题 I want to calculate growth rates in Stata for observations having the same ID. My data looks like this in a simplified way: ID year a b c d e f 10 2010 2 4 9 8 4 2 10 2011 3 5 4 6 5 4 220 2010 1 6 11 14 2 5 220 2011 6 2 12 10 5 4 334 2010 4 5 4 6 1 4 334 2011 5 5 4 4 3 2 Now I want to calculate for each ID growth rates from variables a-f from 2010 to 2011: For e.g ID 10 and variable a it would be: (3-2)/2, for variable b : (5-4)/4 etc. and store the results in new variables (e.g. growth_a ,

Does Stata choke on matrices named “P”?

天大地大妈咪最大 提交于 2019-12-11 10:49:25
问题 So defining a matrix named "Z", and displaying its first element works nicely: . matrix Z = J(1,3,0) . matrix list Z Z[1,3] c1 c2 c3 r1 0 0 0 . di el(Z,1,1) 0 On the other hand simply changing the name to "P" breaks the function of el() : . matrix P = J(1,3,0) . matrix list P P[1,3] c1 c2 c3 r1 0 0 0 . di el(P,1,1) type mismatch Why? Update 1: While finding the above behavior (during a debug session), I reproduced from command line and from an ado file, then reproduced after clearing Stata

Find social network components in Stata

南笙酒味 提交于 2019-12-11 10:39:18
问题 [I copied part of the below example from a separate post and changed it to suit my specific needs] pos_1 pos_2 2 4 2 5 1 2 3 9 4 2 9 3 The above is read as person_2 is connected to person_4,...,person_4 is connected to person_2, and person_9 is connected to person_3. I want to create a third categorical [edited] variable, component, that lets me know if the observed link is part of a connected component (subnetwork) within this network. In this case, there are two connected components in the

How to plot the different graphs by stcurve in one chart in Stata?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 09:59:39
问题 I am using stcurve in Stata to plot survival probability. I need to plot the graph for all data and then for specific variables. I can generate the graphs in two different charts, but I need to have all three lines together in one chart. I have tried the addplot() option but I get the error that stcurve is not a twoway graph. Do you have any idea how to do this? This is the code that I have used which generates the graphs in two different charts separately: stcurve, survival graphregion

Change how time portion of the date is displayed on graph

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 09:54:52
问题 Here is a reproducible example produced by dataex * Example generated by -dataex-. To install: ssc install dataex clear input str23 eventname str10(eventdate scrapedate) byte pricepart float(thpercentile median v7 mean) str5 timestamp str19 datetime "Home Team vs. Away Team" "2016-01-03" "2015-12-04" 1 117.02 153.635 215.135 178.74034 "07:59" "2015-12-04 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-04" 2 117.02 153.635 215.135 178.74034 "16:00" "2015-12-04 16:00:00" "Home Team vs

Stata: Counting number of consecutive occurrences of a pre-defined length

不打扰是莪最后的温柔 提交于 2019-12-11 08:34:08
问题 Observations in my data set contain the history of moves for each player. I would like to count the number of consecutive series of moves of some pre-defined length (2, 3 and more than 3 moves) in the first and the second halves of the game. The sequences cannot overlap, i.e. the sequence 1111 should be considered as a sequence of the length 4, not 2 sequences of length 2. That is, for an observation like this: +-------+-------+-------+-------+-------+-------+-------+-------+ | Move1 | Move2

Insert text in a specific location of a graph

馋奶兔 提交于 2019-12-11 08:03:27
问题 I have two functions y=5*x+3 and y=8*x+2 . After i type the command: graph twoway (function y=5*x+3) (function y=8*x+2) I can use the graphics editor to write text near the intersection of the two lines. However, I would not like to do this all the time. Is there a way to create the graph with the text without adding it later? 回答1: There is a text option for the graph twoway command that does this. First, you obviously need to solve for x and then get the value of y : 5x + 3 = 8x + 2 x = (-3

Exporting matrix from Stata 12 to Excel or MATLAB

强颜欢笑 提交于 2019-12-11 07:27:35
问题 I need to export a matrix of regression results from Stata to MATLAB. I have tried using the Stata command matwrite without success (I get an unrecognized command error). Here is that attempt: ... *Regression 1 reg invlrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq /// lannxt lannxtsq lrlanxtsq pkgamz if invlrevcrp_CAm071~=. reg lrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq /// lannxt lannxtsq lrlanxtsq lpkgamz * Store results mat coef=get(_b) *Export to matlab matwrite using "Z:\Thesis