Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Using regexr() in local macros without using an = sign


From   Abe N <[email protected]>
To   [email protected]
Subject   st: Using regexr() in local macros without using an = sign
Date   Tue, 27 Nov 2012 20:55:42 -0800 (PST)

Hi Everyone,

This is my first time posting something, so I hope this works and sorry in advance if I messed something up.  I've been trying to write a program that at the basics of it runs a series of logistic regressions and while I got it to work for the most part, I've been trying to do something specifically with factor variables (I'm using version 11.2 STATA/SE)

What I'm trying to do currently I think is pretty basic.  I'm starting with a variable list that has factor variables (ex. my current varlist will basically contain: dependent_variable i.age_cat i.year female), expanding it, and then trying to create two new macros, one that contains the base variables (ex. 0b.age_cat 1998b.year) and another that contains the rest (ex. died 1.age_cat 2.age_cat 1999.year 2000.year 2001.year female).

The way I went about this at first worked well for a couple variables, but I was running into the issue of character limits when you evaluate a macro with an = sign.  Here's the code I was using:
    fvexpand `varlist'
    local varlist = "`r(varlist)'"
    local nobases = "`varlist'"
    local loopvar = regexm("`nobases'", "[a-zA-Z0-9]+[b][\.][a-zA-Z0-9_]+[ ]*")
    local onlybases
    while "`loopvar'"=="1" {
      local onlybases = "`onlybases' "+regexs(0)
      local nobases = regexr("`nobases'", "[a-zA-Z0-9]+[b][\.][a-zA-Z0-9_]+[ ]*", "")
      local loopvar = regexm("`nobases'", "[a-zA-Z0-9]+[b][\.][a-zA-Z0-9_]+[ ]*")
    }
    local varlist "`nobases'"
Then when I run logistics later, I would basically use:
    logistic `nobases' `onlybases'

The problem with this method is the macro `nobases' will cut off after a certain # of characters.  So I tried doing things without = signs, but I've been running into a lot of problems because I'm using the regexr() command and it doesn't seem to like me using that without an = sign.  

Now that I've written this up, I'm wondering if this would have been a lot easier using tokenize, but I think I avoided it because I use it later for a very key aspect of the program and I think I was worried it might mess with some of my later loops.  Anyway, any help would be much appreciated.

Thanks,

Abe N.
[email protected]


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index