Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to generate a string of repeated 0s like "00000" in STATA?

    Hi, all,
    I know that we can use STATA command gen new_variable="00000" to generate a new string variable, having 5 zeros in total.
    However, I don't want to use this method to do the same work. Is there an alternative to do this in STATA like function or programming?

    Thank you!

  • #2
    I don't know about STATA (please read the FAQ Advice down to #18) but in Stata you can write

    Code:
    . gen new_variable= 5 * "0"
    
    . di new_variable[1]
    00000
    This hasn't been possible since string variables were added, so if you have a very old version of Stata, it won't work.

    Comment


    • #3
      Thank you for your kindly help. Honestly, I can not distinguish between STATA and Stata. Now that you pointed out this issue, I learned it.

      Comment

      Working...
      X