# loop

1. ### Loops in SPSS - creating new variable based on multiple loops??

Hi, I am looking for help! Maybe someone here knows the answer? I want to make a new variable (in SPSS) Date_flare_FU (Date of a disease flare during follow up). This variable will be based on 12 follow up visits (Date_T1 tm Date_T12 -> date), during which disease activity is assessed...
2. ### Looking for appropriate loop

Hi! Hello! I am looking for solution which lead me from yellow to green results like that: As you can see, there are 0-1 coding data with sysmis, always five 1 per line. Thre are 20 variables (p1,p2, ..., p20) and I need to recode them into 5, using number of columns. I have started with...
3. ### How to duplicate cases in one date set order to match the other before merging

Hi! I have two data sets which I need to merge. 1) demographic data (=one ID per row) 2) Up to 5 duplicates of each ID with different entries per row. Now I can't just delete the duplicates in order to merge the sets as each entry in (2) is important. Also,the data is quite larger...
4. ### Do Loop with IF in Macro

Hi, I've been struggling with a do loop in SAS and would be grateful for any assistance. This is the data I have: data have; input Parameter $COL1$ COL2 \$; cards; Intercept AGE DRINKPATTERN DRINKPATTERN AGE DRINKPATTERN DRINKPATTERN AGE DRINKPATTERN DRINKPATTERN AGE...
5. ### How to write an easy for loop for my function in RStudio? (R script below)

I received an R script from my prof., it can convert an input adjacency matrix to a network format output. It works properly. I'd like to write a for loop to make the file converting faster. My input files are in .csv format: ["a (1).csv", ..., "a (128).csv"]. This is my code: for(x in...
6. ### Base R: add points() in a loop defined by group

Dear all, I am looking for a way to generate different plots in base R with adding points and lines manually to the plot. Here is my sample data: xy <- data.frame(NAME=c("NAME1","NAME1","NAME2","NAME2"), X_START_YEAR=c(1984,1986,1899,1903)...
7. ### Loop through values - only first element is used

Hi everybody, i feel this is very baisc but i need a hand. I want to use the strsplitfunction on characters in a data.frame but under certain conditions! If the condition is met --> split character and take the first two stringparts If the condition is not met --> split the character and take...
8. ### Reshaping data

Hi, I have a data frame which looks like : Jan_V Jan_S Feb_V Feb_S 1 100 90 120 110 2 123 88 112 120 3 121 89 134 130 There are around 200 rows. The data frame can have additional month columns i.e. Mar_V...
9. ### replacing missing values for zeros in a loop

Hello Stata experts, I am working in panel data with dyadic data and years. My data base is like the following: pair year fdi 1 2005 . 1 2006 . 1 2007 . 1 2008 . 1 2009 0 1 2010 0 1 2011 0 2 2005 . 2 2006 . 2 2007 . 2 2008 0 2 2009 0 2 2010 . 2 2011 . 3 2005 . 3 2006 . 3 2007 . 3 2008 2 3 2009 4...
10. ### SAS Loop

Hello community I am having problems in making SAS do this statements for several times: I want the code to execute first with i = 1, then with i = 2 and so on... I know is a basic doubt, but I'd appreciate your help. Best regards proc sort data=Outlets_new; by restatementGroup; run...
11. ### plots and loops with panel data

Hey, my questions: 1. What is the command for a plot of PersonA money against time? 2. I need a for loop over the string variable person which applies a function (e.g. mean of money from 2000 to 2002). Data: year, person, money 2000, PersonA, 100 2000, PersonB, 200...
12. ### Create multiple cases through syntax

Hi! I need to create a set of data in SPSS containing two variables: HOUSEHOLD NUMBER (1000 households, but the numbers of the households are not from 1 to 1000) and MONTH (12 months for 5 years). For each month for each household there should be a separate case, 60 cases per household in...
13. ### quick way to repeat code?

Hi All! This is my first post on this website (have been reading it for months though) so please bear with me if I don't do things right :) The question I need to answer is how many rolls of a dice (in this case with 10 sides) it takes before I have seen every side. From that I need to say...
14. ### iteration using a loop in R

Hi, I have two vectors as follows: popd = vector(mode='numeric', 100) popr = vector(mode='numeric', 100) These represent the initial distribution within 2 populations. I want to define these e.g. popd[]=0.01 popr[]=0.01 These populations will then transform according to the following...
15. ### Loop within subgroup

I'm trying to have R go through a loop within ID groups, and within each group: - find the max year; - count the number of prior observations (by year) that have a code other than the code corresponding to the current row; - disregard observations that appear in the same year. I would very...
16. ### Split Vector and apply Mann Kendall test

I have a long vector of financial time series information, price and volume. I expand the price vector based on the volume vector so I essentially get a price per share traded, and so only one vector is analyzed. I would like to split this vector into lengths of 17500 each, and apply the...
17. ### Conditional Probability

I am trying to create a matrix of the conditional probabilities from this: Signal <- runif(100) PercChange <- abs((rnorm(100)/100)) signalt <- seq(0, 1, 0.05) abst <- seq(0, c(0.02:1), 0.0025) CondDistMat <- matrix(0, nrow = length(signalt), ncol = length(abst)) for(j in...
18. ### Loop do-file with a few adjustments

Hey guys. So I've made a long do-file and I was wondering if there were a clever way to repeat parts of the do-file with a few changes? I'm doing a series of cross-national tests and I want to see what happens if I drop a single country and run all the tests again. Basicly I want this...
19. ### Optimization of While and For loops

Hi I am relatively new to R and have been using an algorithm for a project. I is in this case about 400 million. It is taking a rather long time to run ~20 - 30 minutes, and I was curious if there was a better way of running this? dPNProbExpand is a vector of probabilities, 1 row...
20. ### Complicated Hierarchical Data: Reshaping or Looping?

Hello Stata Wizards, hope one of you can help me with my problem. I have hierarchical data that is a little complicated: I want to try and reshape. Office_ID and Branch names are corresponding. Employee_ID is unique for every employee. The Account_ID often has multiple entries for...