Announcement

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

  • Saving and displaying a table of over 400 univariate regression results

    Hi all,

    I am trying to figure out how to create a table in STATA of multiple (over 400) univariate regression results in one table. For example, my dataset involves understanding the association of spirometry results (fev1 and fvc z score) and metabolomics. The list of metabolomics in my dataset is ~400, and I have to write a code that would run a regression of fev1/fvc z score and each individual metabolite first (which I have done using the foreach command).

    foreach x of varlist lglucuronicacid lhydroxybutanoicacid lisoleucine lornithine lglycerolalphaphosphate lthreonine lazelaicacid lmalicacid lketoisocaproicacid lmethanolphosphate lmyoinositol lasparticacid lphenylalanine lsucrose lasparagine lcreatinine lglycine lpelargonicacid lmethionine lcapricacid lmaltose ltrehalose ludpglucuronicacid llyxitol larabitol lhistidine lcholesterol lhydroxyglutaricacid lpipecolinicacid lglucose1phosphate lethanolamine linositol4monophosphate lpalmiticacid lglutaricacid laminomalonate lisothreonicacid lhydroxyvalericacid lshikimicacid llysine lsuccinicacid lheptadecanoicacid........{
    quietly: regress fev1fvc_z `x' if month==6
    quietly: regress fev1fvc_z `x' if month==2
    quietly: regress fev1fvc_z `x' if month==0
    }

    I cannot figure out how to store these estimates and get a table/export the regression outputs for each metabolite. I have tried looking for a solution in the forums, but nothing works. Any help would be much appreciated as I am relatively new to STATA

    Thank you
    Last edited by Anurima Baidya; 14 Aug 2023, 10:42.

  • #2
    I think a table with the results of 1200 regressions is unlkely to be useful, or even usable. You would be much better off creating a data set containing the results so that you can sort them, select subsets to work with, and perhaps perform calculations on the results. The following code will do that for you:
    Code:
    frame create results str32 metabolite int month float(b se p)
    foreach x of varlist lglucuronicacid lhydroxybutanoicacid lisoleucine lornithine///
        lglycerolalphaphosphate lthreonine lazelaicacid lmalicacid ///
        lketoisocaproicacid lmethanolphosphate lmyoinositol lasparticacid ///
        lphenylalanine lsucrose lasparagine lcreatinine lglycine lpelargonicacid ////
        lmethionine lcapricacid lmaltose ltrehalose ludpglucuronicacid llyxitol ///
        larabitol lhistidine lcholesterol lhydroxyglutaricacid lpipecolinicacid ///
        lglucose1phosphate lethanolamine linositol4monophosphate lpalmiticacid ///
        lglutaricacid laminomalonate lisothreonicacid lhydroxyvalericacid ///
        lshikimicacid llysine lsuccinicacid lheptadecanoicacid /*etc.*/ {
            foreach m of numlist 0 2 6 {
                quietly regress fev1fvc_z `x' if month == `m'
                matrix M = r(table)
                frame post results ("`x'") (`m') (M["b", "`x'"]) (M["se", "`x'"]) ///
                    (M["pvalue", "`x'"])
            }
    }
    frame change results
    At the end of this code, frame results will be the active frame and will contain a Stata data set whose variables are the name of the metabolite, the month, and the regression coefficient along with its standard error and p-value.

    Note: I am assuming that for each metabolite there will be at least 2 observations for each month with non-missing values of both fev1fvc_z and the metabolite variable. If the data ever falls short of that, the regression for that metabolite and that month will be impossible, and that error will cause Stata to halt with an error message. There is a workaround to deal with this, but based on how metabolomics studies are usually done, with large sample sizes, I think it is very unlikely that this situation will arise, so it is best not to complicate the code with fallback code that probably will not be needed. If you do run into this situation, do post back.

    Added: I have also assumed you are not interested in the constant terms from these regressions.
    Last edited by Clyde Schechter; 14 Aug 2023, 11:34.

    Comment


    • #3
      Hello Clyde,

      Thank you so much for the prompt response. This code has worked, and I can make individual datasets now with the regression results. Truly grateful for your help.

      Comment

      Working...
      X