0

I have a variable called "count," which contains the number of subjects who attend each of 1300 study visits. I would like to store these values in a local macro and display them one by one using a for loop.

E.g.,

local count_disp = count
    
forvalues i = 1/1300 {
    
    disp `i' of `count_disp'

}

However, I'm unsure how to store the entire list of the count variable in a macro or how to call each "word" in the macro.

Is this possible in Stata?

jos0909
  • 55
  • 5
  • Please elaborate on what you are trying to do. It is rarely the end goal to display something. Is it the macro of all values that is important to you? If it truly is just to look at the values you can just use the browse window. But my guess is that it is something else. Please elaborate. – TheIceBear May 12 '22 at 16:09
  • I am creating a table that displays the visit number and the count of subjects at each visit. The code you provided works perfectly alongside my 'forvalues' loop to display the visit number. – jos0909 May 12 '22 at 17:33
  • The last sounds like a variation on `tabulate`. – Nick Cox May 12 '22 at 18:38

1 Answers1

0

In case you only want to display all values in order, then it is easier to skip the intermediate step of creating the macro. You can just display the values row by row like this:

* Example generated by -dataex-. For more info, type help dataex
clear
input byte count
11
22
33
end

* Loop over the number of observation and display 
* the value of variable count for that row number
count
forvalues i = 1/`r(_N)' {
    
  * Display value
  display count[`i']
}
TheIceBear
  • 2,912
  • 9
  • 23