Arrays / Vector equivalent in Stata
Asked Answered
W

3

6

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).

Weber answered 2/11, 2013 at 22:16 Comment(0)
P
3

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).

Palpable answered 3/11, 2013 at 5:59 Comment(0)
P
2

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.

Pacify answered 2/11, 2013 at 23:48 Comment(0)
S
1

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

Sunnisunnite answered 3/11, 2013 at 1:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.