4
votes

Being familiar with R, I'm wondering what is the Stata equivalent of vectors (e.g. var<-c(1,2,3,4) )?

I know that Stata uses macros, but I don't get how you can store multiple values in one macro (create an array type of macro).

I want to loop over some strings and use them as patterns for matching regular expressions, like with subinword(columnA,pattern,"substitute",1).

3

3 Answers

2
votes

Macros are flexible creatures and they may be able to help you with whatever it is you want to do (it's not clear). This contains some nice explanations

http://www.ssc.wisc.edu/sscc/pubs/stata_prog1.htm

For array-like structures composed with macros, see for example,

http://www.stata.com/support/faqs/data-management/implement-sas-arrays/

You also mention regular expressions which Stata covers with regex functions (as already suggested in a previous answer).

2
votes

I can think of Mata in Stata for that:

mata
var=1,2,3,4
 var
       1   2   3   4
    +-----------------+
  1 |  1   2   3   4  |
    +-----------------+
end

Have a look at help regex for the regular expressions in Stata. Without any example, it's not clearer to me what you wanted to do.

1
votes

In Stata you can have matrices, and thus vectors as a special case. You can store strings in string variables or in a macro or or in string scalar. If need be, space separated words can be stored in single macros. In Mata strings can also be put in vectors or matrices.

Note that Stata's string functions are documented under help functions, including subinstr() and word().

Please note also http://www.stata.com/support/faqs/resources/statalist-faq/#spell