Announcement

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

  • using "program" command and applying the "program" created

    Hello,

    I created this program, which I am trying to apply in the code later:

    program fixK
    renvars q11-q20 , prefix(temp)

    rename tempq11 q1
    rename tempq12 q2
    rename tempq13 q3
    rename tempq14 q4
    rename tempq15 q5
    rename tempq16 q6
    rename tempq17 q7
    rename tempq18 q8
    rename tempq19 q9
    rename tempq20 q10
    end



    This program was later applied to:

    import excel "C:\Users\name\Desktop\folder\file.xlsx", sheet("Sheet1") firstrow clear
    fixK
    renvars * , prefix(a_)


    When I run the "program" command, it runs fine. However, when I run "fixK" command later to apply to the dataset, it gives me an error message saying "variable tempq11 is not found (r111)".

    I need to give the dataset a set of temp numbers because while trying to merge two datasets, I realized that one of the datasets had numberings off. Please help.

    Thank you so much!

  • #2
    -renvars- is a user-written program that I am not familiar with, and it may be that you are doing something problematic for it. I don't see anything wrong with the way you have defied your program, nor how you have invoked it. But it seems to me that you have written a program and many lines of complicated code when all you need is one line to rename q11 through q20 to q1 through q10:

    Code:
    rename q# q#, renumber
    This assumes that the only variable names in the data that are q followed by a number are q11 through q20, and that they appear in that order in the data set.

    If this does not fit your situation, please post back and provide an example of your data set (i.e., the Stata data set as it appears immediately after the -import excel- command), using the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Hello Clyde!

      Thank you so much for your help. I used the -rename- command for each of the individual variables and it worked fine!

      Comment

      Working...
      X